194 lines · plain
1; RUN: llc < %s2 3%Domain = type { ptr, i32, ptr, i32, i32, ptr, ptr }4@AConst = constant i32 123 ; <ptr> [#uses=1]5 6; Test setting values of different constants in registers.7; 8define 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]12 %c = fadd float %X, 0.000000e+00 ; <float> [#uses=0]13 %d = fadd float %X, 0x400921CAC0000000 ; <float> [#uses=0]14 %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 void20}21 22; A SetCC whose result is used should produce instructions to23; compute the boolean value in a register. One whose result24; is unused will only generate the condition code but not25; the boolean result.26; 27define void @unusedBool(ptr %x, ptr %y) {28 icmp eq ptr %x, %y ; <i1>:1 [#uses=1]29 xor i1 %1, true ; <i1>:2 [#uses=0]30 icmp ne ptr %x, %y ; <i1>:3 [#uses=0]31 ret void32}33 34; A constant argument to a Phi produces a Cast instruction in the35; corresponding predecessor basic block. This checks a few things:36; -- phi arguments coming from the bottom of the same basic block37; (they should not be forward substituted in the machine code!)38; -- code generation for casts of various types39; -- use of immediate fields for integral constants of different sizes40; -- branch on a constant condition41; 42define void @mergeConstants(ptr %x, ptr %y) {43; <label>:044 br label %Top45 46Top: ; preds = %Next, %Top, %047 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 %Next52 53Next: ; preds = %Top54 br label %Top55}56 57 58 59; A constant argument to a cast used only once should be forward substituted60; and loaded where needed, which happens is:61; -- User of cast has no immediate field62; -- User of cast has immediate field but constant is too large to fit63; 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 implicit65; use but has to be loaded into a virtual register so that the reg.66; allocator can allocate the appropriate phys. reg. for it67; 68define ptr @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 %dummyl = load i64, ptr @AConst ; <i64> [#uses=0]73 %castnull = inttoptr i64 0 to ptr ; <ptr> [#uses=1]74 ret ptr %castnull75}76 77; Test branch-on-comparison-with-zero, in two ways:78; 1. can be folded79; 2. cannot be folded because result of comparison is used twice80;81define void @testbool(i32 %A, i32 %B) {82 br label %Top83 84Top: ; preds = %loop, %085 %D = add i32 %A, %B ; <i32> [#uses=2]86 %E = sub i32 %D, -4 ; <i32> [#uses=1]87 %C = icmp sle i32 %E, 0 ; <i1> [#uses=1]88 br i1 %C, label %retlbl, label %loop89 90loop: ; preds = %loop, %Top91 %F = add i32 %A, %B ; <i32> [#uses=0]92 %G = sub i32 %D, -4 ; <i32> [#uses=1]93 %D.upgrd.1 = icmp sle i32 %G, 0 ; <i1> [#uses=1]94 %E.upgrd.2 = xor i1 %D.upgrd.1, true ; <i1> [#uses=1]95 br i1 %E.upgrd.2, label %loop, label %Top96 97retlbl: ; preds = %Top98 ret void99}100 101 102;; Test use of a boolean result in cast operations.103;; Requires converting a condition code result into a 0/1 value in a reg.104;; 105define i32 @castbool(i32 %A, i32 %B) {106bb0:107 %cond213 = icmp slt i32 %A, %B ; <i1> [#uses=1]108 %cast110 = zext i1 %cond213 to i8 ; <i8> [#uses=1]109 %cast109 = zext i8 %cast110 to i32 ; <i32> [#uses=1]110 ret i32 %cast109111}112 113;; Test use of a boolean result in arithmetic and logical operations.114;; Requires converting a condition code result into a 0/1 value in a reg.115;; 116define i1 @boolexpr(i1 %b, i32 %N) {117 %b2 = icmp sge i32 %N, 0 ; <i1> [#uses=1]118 %b3 = and i1 %b, %b2 ; <i1> [#uses=1]119 ret i1 %b3120}121 122; Test branch on floating point comparison123;124define void @testfloatbool(float %x, float %y) {125 br label %Top126 127Top: ; preds = %Top, %0128 %p = fadd float %x, %y ; <float> [#uses=1]129 %z = fsub float %x, %y ; <float> [#uses=1]130 %b = fcmp ole float %p, %z ; <i1> [#uses=2]131 %c = xor i1 %b, true ; <i1> [#uses=0]132 br i1 %b, label %Top, label %goon133 134goon: ; preds = %Top135 ret void136}137 138 139; Test cases where an LLVM instruction requires no machine140; instructions (e.g., cast int* to long). But there are 2 cases:141; 1. If the result register has only a single use and the use is in the142; same basic block, the operand will be copy-propagated during143; instruction selection.144; 2. If the result register has multiple uses or is in a different145; basic block, it cannot (or will not) be copy propagated during146; instruction selection. It will generate a147; copy instruction (add-with-0), but this copy should get coalesced148; away by the register allocator.149;150define i32 @checkForward(i32 %N, ptr %A) {151bb2:152 %reg114 = shl i32 %N, 2 ; <i32> [#uses=1]153 %cast115 = sext i32 %reg114 to i64 ; <i64> [#uses=1]154 %cast116 = ptrtoint ptr %A to i64 ; <i64> [#uses=1]155 %reg116 = add i64 %cast116, %cast115 ; <i64> [#uses=1]156 %castPtr = inttoptr i64 %reg116 to ptr ; <ptr> [#uses=1]157 %reg118 = load i32, ptr %castPtr ; <i32> [#uses=1]158 %cast117 = sext i32 %reg118 to i64 ; <i64> [#uses=2]159 %reg159 = add i64 1234567, %cast117 ; <i64> [#uses=0]160 %reg160 = add i64 7654321, %cast117 ; <i64> [#uses=0]161 ret i32 0162}163 164 165; Test case for unary NOT operation constructed from XOR.166; 167define void @checkNot(i1 %b, i32 %i) {168 %notB = xor i1 %b, true ; <i1> [#uses=1]169 %notI = xor i32 %i, -1 ; <i32> [#uses=2]170 %F = icmp sge i32 %notI, 100 ; <i1> [#uses=1]171 %J = add i32 %i, %i ; <i32> [#uses=1]172 %andNotB = and i1 %F, %notB ; <i1> [#uses=0]173 %andNotI = and i32 %J, %notI ; <i32> [#uses=0]174 %notB2 = xor i1 true, %b ; <i1> [#uses=0]175 %notI2 = xor i32 -1, %i ; <i32> [#uses=0]176 ret void177}178 179; Test case for folding getelementptr into a load/store180;181define i32 @checkFoldGEP(ptr %D, i64 %idx) {182 %reg841 = getelementptr %Domain, ptr %D, i64 0, i32 1 ; <ptr> [#uses=1]183 %reg820 = load i32, ptr %reg841 ; <i32> [#uses=1]184 ret i32 %reg820185}186 187; Test case for scalarising a 1 element vselect188;189define <1 x i32> @checkScalariseVSELECT(<1 x i32> %a, <1 x i32> %b) {190 %cond = icmp uge <1 x i32> %a, %b191 %s = select <1 x i1> %cond, <1 x i32> %a, <1 x i32> %b192 ret <1 x i32> %s193}194