brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.2 KiB · 46bd7cf Raw
150 lines · plain
1; RUN: opt -S -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 2>&1 | FileCheck %s2 3; umin is represented using -1 * umax in scalar evolution. -1 is considered as the4; constant of the multiply expression (-1 * ((-1 + (-1 * %a)) umax (-1 + (-1 * %b)))).5; Returns the greatest power of 2 divisor by evaluating the minimal trailing zeros6; for the trip count expression.7;8; int foo(uint32_t a, uint32_t b, uint32_t *c) {9;   for (uint32_t i = 0; i < (uint32_t)(a < b ? a : b) + 1; i++)10;     c[i] = i;11;   return 0;12; }13;14; CHECK: Loop %for.body: Trip multiple is 115 16define i32 @foo(i32 %a, i32 %b, ptr %c) {17entry:18  %cmp = icmp ult i32 %a, %b19  %cond = select i1 %cmp, i32 %a, i32 %b20  %add = add i32 %cond, 121  %cmp18 = icmp eq i32 %add, 022  br i1 %cmp18, label %for.cond.cleanup, label %for.body.preheader23 24for.body.preheader:                               ; preds = %entry25  br label %for.body26 27for.cond.cleanup.loopexit:                        ; preds = %for.body28  br label %for.cond.cleanup29 30for.cond.cleanup:                                 ; preds = %for.cond.cleanup.loopexit, %entry31  ret i32 032 33for.body:                                         ; preds = %for.body.preheader, %for.body34  %i.09 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]35  %arrayidx = getelementptr inbounds i32, ptr %c, i32 %i.0936  store i32 %i.09, ptr %arrayidx, align 437  %inc = add nuw i32 %i.09, 138  %cmp1 = icmp ult i32 %inc, %add39  br i1 %cmp1, label %for.body, label %for.cond.cleanup.loopexit40}41 42; Overflow may happen for the multiply expression n * 3, verify that trip43; multiple is set to 1 if NUW/NSW are not set.44;45; __attribute__((noinline)) void a(unsigned n) {46;   #pragma unroll(3)47;   for (unsigned i = 0; i != n * 3; ++i)48;     printf("TEST%u\n", i);49; }50; int main() { a(2863311531U); }51;52; CHECK: Loop %for.body: Trip multiple is 153 54@.str2 = private unnamed_addr constant [8 x i8] c"TEST%u\0A\00", align 155 56define void @foo2(i32 %n) {57entry:58  %mul = mul i32 %n, 359  %cmp4 = icmp eq i32 %mul, 060  br i1 %cmp4, label %for.cond.cleanup, label %for.body.preheader61 62for.body.preheader:                               ; preds = %entry63  br label %for.body64 65for.cond.cleanup.loopexit:                        ; preds = %for.body66  br label %for.cond.cleanup67 68for.cond.cleanup:                                 ; preds = %for.cond.cleanup.loopexit, %entry69  ret void70 71for.body:                                         ; preds = %for.body.preheader, %for.body72  %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]73  %call = tail call i32 (ptr, ...) @printf(ptr @.str2, i32 %i.05)74  %inc = add nuw i32 %i.05, 175  %cmp = icmp eq i32 %inc, %mul76  br i1 %cmp, label %for.cond.cleanup.loopexit, label %for.body77}78 79declare i32 @printf(ptr nocapture readonly, ...)80 81 82; If we couldn't prove no overflow for the multiply expression 24 * n,83; returns the greatest power of 2 divisor. If overflows happens84; the trip count is still divisible by the greatest power of 2 divisor.85;86; CHECK: Loop %l3: Trip multiple is 887 88declare void @f()89 90define i32 @foo3(i32 %n) {91entry:92  %loop_ctl = mul i32 %n, 2493  br label %l394 95l3:96  %x.0 = phi i32 [ 0, %entry ], [ %inc, %l3 ]97  call void @f()98  %inc = add i32 %x.0, 199  %exitcond = icmp eq i32 %inc, %loop_ctl100  br i1 %exitcond, label %exit, label %l3101 102exit:103  ret i32 0104}105 106; If the trip count is a constant, verify that we obtained the trip107; count itself. For huge trip counts, or zero, we return 1.108;109; CHECK: Loop %l3: Trip multiple is 3110 111define i32 @foo4(i32 %n) {112entry:113  br label %l3114 115l3:116  %x.0 = phi i32 [ 0, %entry ], [ %inc, %l3 ]117  call void @f()118  %inc = add i32 %x.0, 1119  %exitcond = icmp eq i32 %inc, 3120  br i1 %exitcond, label %exit, label %l3121 122exit:123  ret i32 0124}125 126; If there are multiple exits, the result is the GCD of the multiples127; of each individual exit (since we don't know which is taken).128 129; CHECK: Loop %l4: Trip multiple is 50130 131define i32 @foo5(i32 %n) {132entry:133  br label %l4134 135l4:136  %x.0 = phi i32 [ 0, %entry ], [ %inc, %l4-latch ]137  call void @f()138  %inc = add i32 %x.0, 1139  %earlycond = icmp eq i32 %inc, 150140  br i1 %earlycond, label %exit, label %l4-latch141 142l4-latch:143  %exitcond = icmp eq i32 %inc, 200144  br i1 %exitcond, label %exit, label %l4145 146exit:147  ret i32 0148}149 150