1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-25 14:02:52 +02:00
llvm-mirror/test/CodeGen/Generic/select.ll

195 lines
7.8 KiB
LLVM
Raw Normal View History

; RUN: llc < %s
2004-11-07 00:08:26 +01:00
%Domain = type { i8*, i32, i32*, i32, i32, i32*, %Domain* }
@AConst = constant i32 123 ; <i32*> [#uses=1]
; Test setting values of different constants in registers.
;
define void @testConsts(i32 %N, float %X) {
%a = add i32 %N, 1 ; <i32> [#uses=0]
%i = add i32 %N, 12345678 ; <i32> [#uses=0]
%b = add i16 4, 3 ; <i16> [#uses=0]
%c = fadd float %X, 0.000000e+00 ; <float> [#uses=0]
%d = fadd float %X, 0x400921CAC0000000 ; <float> [#uses=0]
%f = add i32 -1, 10 ; <i32> [#uses=0]
%g = add i16 20, -1 ; <i16> [#uses=0]
%j = add i16 -1, 30 ; <i16> [#uses=0]
%h = add i8 40, -1 ; <i8> [#uses=0]
%k = add i8 -1, 50 ; <i8> [#uses=0]
ret void
}
; A SetCC whose result is used should produce instructions to
; compute the boolean value in a register. One whose result
; is unused will only generate the condition code but not
; the boolean result.
;
define void @unusedBool(i32* %x, i32* %y) {
icmp eq i32* %x, %y ; <i1>:1 [#uses=1]
xor i1 %1, true ; <i1>:2 [#uses=0]
icmp ne i32* %x, %y ; <i1>:3 [#uses=0]
ret void
}
; A constant argument to a Phi produces a Cast instruction in the
; corresponding predecessor basic block. This checks a few things:
; -- phi arguments coming from the bottom of the same basic block
; (they should not be forward substituted in the machine code!)
; -- code generation for casts of various types
; -- use of immediate fields for integral constants of different sizes
; -- branch on a constant condition
;
define void @mergeConstants(i32* %x, i32* %y) {
; <label>:0
br label %Top
Top: ; preds = %Next, %Top, %0
phi i32 [ 0, %0 ], [ 1, %Top ], [ 524288, %Next ] ; <i32>:1 [#uses=0]
phi float [ 0.000000e+00, %0 ], [ 1.000000e+00, %Top ], [ 2.000000e+00, %Next ] ; <float>:2 [#uses=0]
phi double [ 5.000000e-01, %0 ], [ 1.500000e+00, %Top ], [ 2.500000e+00, %Next ]
phi i1 [ true, %0 ], [ false, %Top ], [ true, %Next ] ; <i1>:4 [#uses=0]
br i1 true, label %Top, label %Next
Next: ; preds = %Top
br label %Top
}
; A constant argument to a cast used only once should be forward substituted
; and loaded where needed, which happens is:
; -- User of cast has no immediate field
; -- User of cast has immediate field but constant is too large to fit
; or constant is not resolved until later (e.g., global address)
; -- User of cast uses it as a call arg. or return value so it is an implicit
; use but has to be loaded into a virtual register so that the reg.
; allocator can allocate the appropriate phys. reg. for it
;
define i32* @castconst(float) {
%castbig = trunc i64 99999999 to i32 ; <i32> [#uses=1]
%castsmall = trunc i64 1 to i32 ; <i32> [#uses=1]
%usebig = add i32 %castbig, %castsmall ; <i32> [#uses=0]
%castglob = bitcast i32* @AConst to i64* ; <i64*> [#uses=1]
%dummyl = load i64, i64* %castglob ; <i64> [#uses=0]
%castnull = inttoptr i64 0 to i32* ; <i32*> [#uses=1]
ret i32* %castnull
}
; Test branch-on-comparison-with-zero, in two ways:
; 1. can be folded
; 2. cannot be folded because result of comparison is used twice
;
define void @testbool(i32 %A, i32 %B) {
br label %Top
Top: ; preds = %loop, %0
%D = add i32 %A, %B ; <i32> [#uses=2]
%E = sub i32 %D, -4 ; <i32> [#uses=1]
%C = icmp sle i32 %E, 0 ; <i1> [#uses=1]
br i1 %C, label %retlbl, label %loop
loop: ; preds = %loop, %Top
%F = add i32 %A, %B ; <i32> [#uses=0]
%G = sub i32 %D, -4 ; <i32> [#uses=1]
%D.upgrd.1 = icmp sle i32 %G, 0 ; <i1> [#uses=1]
%E.upgrd.2 = xor i1 %D.upgrd.1, true ; <i1> [#uses=1]
br i1 %E.upgrd.2, label %loop, label %Top
retlbl: ; preds = %Top
ret void
}
;; Test use of a boolean result in cast operations.
;; Requires converting a condition code result into a 0/1 value in a reg.
;;
define i32 @castbool(i32 %A, i32 %B) {
bb0:
%cond213 = icmp slt i32 %A, %B ; <i1> [#uses=1]
%cast110 = zext i1 %cond213 to i8 ; <i8> [#uses=1]
%cast109 = zext i8 %cast110 to i32 ; <i32> [#uses=1]
ret i32 %cast109
}
;; Test use of a boolean result in arithmetic and logical operations.
;; Requires converting a condition code result into a 0/1 value in a reg.
;;
define i1 @boolexpr(i1 %b, i32 %N) {
%b2 = icmp sge i32 %N, 0 ; <i1> [#uses=1]
%b3 = and i1 %b, %b2 ; <i1> [#uses=1]
ret i1 %b3
}
; Test branch on floating point comparison
;
define void @testfloatbool(float %x, float %y) {
br label %Top
Top: ; preds = %Top, %0
%p = fadd float %x, %y ; <float> [#uses=1]
%z = fsub float %x, %y ; <float> [#uses=1]
%b = fcmp ole float %p, %z ; <i1> [#uses=2]
%c = xor i1 %b, true ; <i1> [#uses=0]
br i1 %b, label %Top, label %goon
goon: ; preds = %Top
ret void
}
; Test cases where an LLVM instruction requires no machine
; instructions (e.g., cast int* to long). But there are 2 cases:
; 1. If the result register has only a single use and the use is in the
; same basic block, the operand will be copy-propagated during
; instruction selection.
; 2. If the result register has multiple uses or is in a different
; basic block, it cannot (or will not) be copy propagated during
; instruction selection. It will generate a
; copy instruction (add-with-0), but this copy should get coalesced
; away by the register allocator.
;
define i32 @checkForward(i32 %N, i32* %A) {
bb2:
%reg114 = shl i32 %N, 2 ; <i32> [#uses=1]
%cast115 = sext i32 %reg114 to i64 ; <i64> [#uses=1]
%cast116 = ptrtoint i32* %A to i64 ; <i64> [#uses=1]
%reg116 = add i64 %cast116, %cast115 ; <i64> [#uses=1]
%castPtr = inttoptr i64 %reg116 to i32* ; <i32*> [#uses=1]
%reg118 = load i32, i32* %castPtr ; <i32> [#uses=1]
%cast117 = sext i32 %reg118 to i64 ; <i64> [#uses=2]
%reg159 = add i64 1234567, %cast117 ; <i64> [#uses=0]
%reg160 = add i64 7654321, %cast117 ; <i64> [#uses=0]
ret i32 0
}
; Test case for unary NOT operation constructed from XOR.
;
define void @checkNot(i1 %b, i32 %i) {
%notB = xor i1 %b, true ; <i1> [#uses=1]
%notI = xor i32 %i, -1 ; <i32> [#uses=2]
%F = icmp sge i32 %notI, 100 ; <i1> [#uses=1]
%J = add i32 %i, %i ; <i32> [#uses=1]
%andNotB = and i1 %F, %notB ; <i1> [#uses=0]
%andNotI = and i32 %J, %notI ; <i32> [#uses=0]
%notB2 = xor i1 true, %b ; <i1> [#uses=0]
%notI2 = xor i32 -1, %i ; <i32> [#uses=0]
ret void
}
; Test case for folding getelementptr into a load/store
;
define i32 @checkFoldGEP(%Domain* %D, i64 %idx) {
[opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction One of several parallel first steps to remove the target type of pointers, replacing them with a single opaque pointer type. This adds an explicit type parameter to the gep instruction so that when the first parameter becomes an opaque pointer type, the type to gep through is still available to the instructions. * This doesn't modify gep operators, only instructions (operators will be handled separately) * Textual IR changes only. Bitcode (including upgrade) and changing the in-memory representation will be in separate changes. * geps of vectors are transformed as: getelementptr <4 x float*> %x, ... ->getelementptr float, <4 x float*> %x, ... Then, once the opaque pointer type is introduced, this will ultimately look like: getelementptr float, <4 x ptr> %x with the unambiguous interpretation that it is a vector of pointers to float. * address spaces remain on the pointer, not the type: getelementptr float addrspace(1)* %x ->getelementptr float, float addrspace(1)* %x Then, eventually: getelementptr float, ptr addrspace(1) %x Importantly, the massive amount of test case churn has been automated by same crappy python code. I had to manually update a few test cases that wouldn't fit the script's model (r228970,r229196,r229197,r229198). The python script just massages stdin and writes the result to stdout, I then wrapped that in a shell script to handle replacing files, then using the usual find+xargs to migrate all the files. update.py: import fileinput import sys import re ibrep = re.compile(r"(^.*?[^%\w]getelementptr inbounds )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))") normrep = re.compile( r"(^.*?[^%\w]getelementptr )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))") def conv(match, line): if not match: return line line = match.groups()[0] if len(match.groups()[5]) == 0: line += match.groups()[2] line += match.groups()[3] line += ", " line += match.groups()[1] line += "\n" return line for line in sys.stdin: if line.find("getelementptr ") == line.find("getelementptr inbounds"): if line.find("getelementptr inbounds") != line.find("getelementptr inbounds ("): line = conv(re.match(ibrep, line), line) elif line.find("getelementptr ") != line.find("getelementptr ("): line = conv(re.match(normrep, line), line) sys.stdout.write(line) apply.sh: for name in "$@" do python3 `dirname "$0"`/update.py < "$name" > "$name.tmp" && mv "$name.tmp" "$name" rm -f "$name.tmp" done The actual commands: From llvm/src: find test/ -name *.ll | xargs ./apply.sh From llvm/src/tools/clang: find test/ -name *.mm -o -name *.m -o -name *.cpp -o -name *.c | xargs -I '{}' ../../apply.sh "{}" From llvm/src/tools/polly: find test/ -name *.ll | xargs ./apply.sh After that, check-all (with llvm, clang, clang-tools-extra, lld, compiler-rt, and polly all checked out). The extra 'rm' in the apply.sh script is due to a few files in clang's test suite using interesting unicode stuff that my python script was throwing exceptions on. None of those files needed to be migrated, so it seemed sufficient to ignore those cases. Reviewers: rafael, dexonsmith, grosser Differential Revision: http://reviews.llvm.org/D7636 llvm-svn: 230786
2015-02-27 20:29:02 +01:00
%reg841 = getelementptr %Domain, %Domain* %D, i64 0, i32 1 ; <i32*> [#uses=1]
%reg820 = load i32, i32* %reg841 ; <i32> [#uses=1]
ret i32 %reg820
}
; Test case for scalarising a 1 element vselect
;
define <1 x i32> @checkScalariseVSELECT(<1 x i32> %a, <1 x i32> %b) {
%cond = icmp uge <1 x i32> %a, %b
%s = select <1 x i1> %cond, <1 x i32> %a, <1 x i32> %b
ret <1 x i32> %s
}