blob: 63052c1a28453de07a890768db055876339639d3 [file] [log] [blame]
Dan Gohmanfce288f2009-09-09 00:09:15 +00001; RUN: llc < %s
Tanya Lattner2393a242004-11-06 23:08:26 +00002
Tanya Lattner53a66d12008-02-19 01:41:04 +00003%Domain = type { i8*, i32, i32*, i32, i32, i32*, %Domain* }
4@AConst = constant i32 123 ; <i32*> [#uses=1]
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +00005
6; Test setting values of different constants in registers.
7;
Tanya Lattner53a66d12008-02-19 01:41:04 +00008define void @testConsts(i32 %N, float %X) {
9 %a = add i32 %N, 1 ; <i32> [#uses=0]
10 %i = add i32 %N, 12345678 ; <i32> [#uses=0]
11 %b = add i16 4, 3 ; <i16> [#uses=0]
Dan Gohmanae3a0be2009-06-04 22:49:04 +000012 %c = fadd float %X, 0.000000e+00 ; <float> [#uses=0]
13 %d = fadd float %X, 0x400921CAC0000000 ; <float> [#uses=0]
Tanya Lattner53a66d12008-02-19 01:41:04 +000014 %f = add i32 -1, 10 ; <i32> [#uses=0]
15 %g = add i16 20, -1 ; <i16> [#uses=0]
16 %j = add i16 -1, 30 ; <i16> [#uses=0]
17 %h = add i8 40, -1 ; <i8> [#uses=0]
18 %k = add i8 -1, 50 ; <i8> [#uses=0]
19 ret void
20}
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +000021
22; A SetCC whose result is used should produce instructions to
23; compute the boolean value in a register. One whose result
24; is unused will only generate the condition code but not
25; the boolean result.
26;
Tanya Lattner53a66d12008-02-19 01:41:04 +000027define void @unusedBool(i32* %x, i32* %y) {
28 icmp eq i32* %x, %y ; <i1>:1 [#uses=1]
29 xor i1 %1, true ; <i1>:2 [#uses=0]
30 icmp ne i32* %x, %y ; <i1>:3 [#uses=0]
31 ret void
32}
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +000033
34; A constant argument to a Phi produces a Cast instruction in the
35; corresponding predecessor basic block. This checks a few things:
36; -- phi arguments coming from the bottom of the same basic block
37; (they should not be forward substituted in the machine code!)
38; -- code generation for casts of various types
39; -- use of immediate fields for integral constants of different sizes
40; -- branch on a constant condition
41;
Tanya Lattner53a66d12008-02-19 01:41:04 +000042define void @mergeConstants(i32* %x, i32* %y) {
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +000043; <label>:0
Tanya Lattner53a66d12008-02-19 01:41:04 +000044 br label %Top
45
46Top: ; preds = %Next, %Top, %0
47 phi i32 [ 0, %0 ], [ 1, %Top ], [ 524288, %Next ] ; <i32>:1 [#uses=0]
48 phi float [ 0.000000e+00, %0 ], [ 1.000000e+00, %Top ], [ 2.000000e+00, %Next ] ; <float>:2 [#uses=0]
49 phi double [ 5.000000e-01, %0 ], [ 1.500000e+00, %Top ], [ 2.500000e+00, %Next ]
50 phi i1 [ true, %0 ], [ false, %Top ], [ true, %Next ] ; <i1>:4 [#uses=0]
51 br i1 true, label %Top, label %Next
52
53Next: ; preds = %Top
54 br label %Top
55}
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +000056
57
58
59; A constant argument to a cast used only once should be forward substituted
60; and loaded where needed, which happens is:
61; -- User of cast has no immediate field
62; -- User of cast has immediate field but constant is too large to fit
63; or constant is not resolved until later (e.g., global address)
64; -- User of cast uses it as a call arg. or return value so it is an implicit
65; use but has to be loaded into a virtual register so that the reg.
66; allocator can allocate the appropriate phys. reg. for it
67;
Tanya Lattner53a66d12008-02-19 01:41:04 +000068define i32* @castconst(float) {
69 %castbig = trunc i64 99999999 to i32 ; <i32> [#uses=1]
70 %castsmall = trunc i64 1 to i32 ; <i32> [#uses=1]
71 %usebig = add i32 %castbig, %castsmall ; <i32> [#uses=0]
72 %castglob = bitcast i32* @AConst to i64* ; <i64*> [#uses=1]
73 %dummyl = load i64* %castglob ; <i64> [#uses=0]
74 %castnull = inttoptr i64 0 to i32* ; <i32*> [#uses=1]
75 ret i32* %castnull
76}
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +000077
78; Test branch-on-comparison-with-zero, in two ways:
79; 1. can be folded
80; 2. cannot be folded because result of comparison is used twice
81;
Tanya Lattner53a66d12008-02-19 01:41:04 +000082define void @testbool(i32 %A, i32 %B) {
83 br label %Top
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +000084
Tanya Lattner53a66d12008-02-19 01:41:04 +000085Top: ; preds = %loop, %0
86 %D = add i32 %A, %B ; <i32> [#uses=2]
87 %E = sub i32 %D, -4 ; <i32> [#uses=1]
88 %C = icmp sle i32 %E, 0 ; <i1> [#uses=1]
89 br i1 %C, label %retlbl, label %loop
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +000090
Tanya Lattner53a66d12008-02-19 01:41:04 +000091loop: ; preds = %loop, %Top
92 %F = add i32 %A, %B ; <i32> [#uses=0]
93 %G = sub i32 %D, -4 ; <i32> [#uses=1]
94 %D.upgrd.1 = icmp sle i32 %G, 0 ; <i1> [#uses=1]
95 %E.upgrd.2 = xor i1 %D.upgrd.1, true ; <i1> [#uses=1]
96 br i1 %E.upgrd.2, label %loop, label %Top
97
98retlbl: ; preds = %Top
99 ret void
100}
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +0000101
102
Vikram S. Adveddd57512002-08-22 03:05:13 +0000103;; Test use of a boolean result in cast operations.
104;; Requires converting a condition code result into a 0/1 value in a reg.
105;;
Tanya Lattner53a66d12008-02-19 01:41:04 +0000106define i32 @castbool(i32 %A, i32 %B) {
107bb0:
108 %cond213 = icmp slt i32 %A, %B ; <i1> [#uses=1]
109 %cast110 = zext i1 %cond213 to i8 ; <i8> [#uses=1]
110 %cast109 = zext i8 %cast110 to i32 ; <i32> [#uses=1]
111 ret i32 %cast109
Vikram S. Adveddd57512002-08-22 03:05:13 +0000112}
113
Vikram S. Adveddd57512002-08-22 03:05:13 +0000114;; Test use of a boolean result in arithmetic and logical operations.
115;; Requires converting a condition code result into a 0/1 value in a reg.
116;;
Tanya Lattner53a66d12008-02-19 01:41:04 +0000117define i1 @boolexpr(i1 %b, i32 %N) {
118 %b2 = icmp sge i32 %N, 0 ; <i1> [#uses=1]
119 %b3 = and i1 %b, %b2 ; <i1> [#uses=1]
120 ret i1 %b3
Vikram S. Adveddd57512002-08-22 03:05:13 +0000121}
122
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +0000123; Test branch on floating point comparison
124;
Tanya Lattner53a66d12008-02-19 01:41:04 +0000125define void @testfloatbool(float %x, float %y) {
126 br label %Top
127
128Top: ; preds = %Top, %0
Dan Gohmanae3a0be2009-06-04 22:49:04 +0000129 %p = fadd float %x, %y ; <float> [#uses=1]
130 %z = fsub float %x, %y ; <float> [#uses=1]
Tanya Lattner53a66d12008-02-19 01:41:04 +0000131 %b = fcmp ole float %p, %z ; <i1> [#uses=2]
132 %c = xor i1 %b, true ; <i1> [#uses=0]
133 br i1 %b, label %Top, label %goon
134
135goon: ; preds = %Top
136 ret void
137}
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +0000138
139
140; Test cases where an LLVM instruction requires no machine
141; instructions (e.g., cast int* to long). But there are 2 cases:
142; 1. If the result register has only a single use and the use is in the
143; same basic block, the operand will be copy-propagated during
144; instruction selection.
145; 2. If the result register has multiple uses or is in a different
146; basic block, it cannot (or will not) be copy propagated during
147; instruction selection. It will generate a
148; copy instruction (add-with-0), but this copy should get coalesced
149; away by the register allocator.
150;
Tanya Lattner53a66d12008-02-19 01:41:04 +0000151define i32 @checkForward(i32 %N, i32* %A) {
152bb2:
153 %reg114 = shl i32 %N, 2 ; <i32> [#uses=1]
154 %cast115 = sext i32 %reg114 to i64 ; <i64> [#uses=1]
155 %cast116 = ptrtoint i32* %A to i64 ; <i64> [#uses=1]
156 %reg116 = add i64 %cast116, %cast115 ; <i64> [#uses=1]
157 %castPtr = inttoptr i64 %reg116 to i32* ; <i32*> [#uses=1]
158 %reg118 = load i32* %castPtr ; <i32> [#uses=1]
159 %cast117 = sext i32 %reg118 to i64 ; <i64> [#uses=2]
160 %reg159 = add i64 1234567, %cast117 ; <i64> [#uses=0]
161 %reg160 = add i64 7654321, %cast117 ; <i64> [#uses=0]
162 ret i32 0
163}
Vikram S. Adve0f63e222002-08-15 14:09:56 +0000164
165
166; Test case for unary NOT operation constructed from XOR.
167;
Tanya Lattner53a66d12008-02-19 01:41:04 +0000168define void @checkNot(i1 %b, i32 %i) {
169 %notB = xor i1 %b, true ; <i1> [#uses=1]
170 %notI = xor i32 %i, -1 ; <i32> [#uses=2]
171 %F = icmp sge i32 %notI, 100 ; <i1> [#uses=1]
172 %J = add i32 %i, %i ; <i32> [#uses=1]
173 %andNotB = and i1 %F, %notB ; <i1> [#uses=0]
174 %andNotI = and i32 %J, %notI ; <i32> [#uses=0]
175 %notB2 = xor i1 true, %b ; <i1> [#uses=0]
176 %notI2 = xor i32 -1, %i ; <i32> [#uses=0]
177 ret void
178}
Vikram S. Advef2899112002-10-13 00:44:00 +0000179
180; Test case for folding getelementptr into a load/store
181;
Tanya Lattner53a66d12008-02-19 01:41:04 +0000182define i32 @checkFoldGEP(%Domain* %D, i64 %idx) {
183 %reg841 = getelementptr %Domain* %D, i64 0, i32 1 ; <i32*> [#uses=1]
184 %reg820 = load i32* %reg841 ; <i32> [#uses=1]
185 ret i32 %reg820
186}
187