Home | History | Annotate | Download | only in ScalarEvolution
      1 ; RUN: opt < %s -S -analyze -scalar-evolution | FileCheck %s
      2 
      3 ; ScalarEvolution should be able to fold away the sign-extensions
      4 ; on this loop with a primary induction variable incremented with
      5 ; a nsw add of 2.
      6 
      7 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
      8 
      9 define void @foo(i32 %no, double* nocapture %d, double* nocapture %q) nounwind {
     10 entry:
     11   %n = and i32 %no, 4294967294
     12   %0 = icmp sgt i32 %n, 0                         ; <i1> [#uses=1]
     13   br i1 %0, label %bb.nph, label %return
     14 
     15 bb.nph:                                           ; preds = %entry
     16   br label %bb
     17 
     18 bb:                                               ; preds = %bb.nph, %bb1
     19   %i.01 = phi i32 [ %16, %bb1 ], [ 0, %bb.nph ]   ; <i32> [#uses=5]
     20 
     21 ; CHECK: %1 = sext i32 %i.01 to i64
     22 ; CHECK: -->  {0,+,2}<nuw><nsw><%bb>
     23   %1 = sext i32 %i.01 to i64                      ; <i64> [#uses=1]
     24 
     25 ; CHECK: %2 = getelementptr inbounds double* %d, i64 %1
     26 ; CHECK: -->  {%d,+,16}<nsw><%bb>
     27   %2 = getelementptr inbounds double* %d, i64 %1  ; <double*> [#uses=1]
     28 
     29   %3 = load double* %2, align 8                   ; <double> [#uses=1]
     30   %4 = sext i32 %i.01 to i64                      ; <i64> [#uses=1]
     31   %5 = getelementptr inbounds double* %q, i64 %4  ; <double*> [#uses=1]
     32   %6 = load double* %5, align 8                   ; <double> [#uses=1]
     33   %7 = or i32 %i.01, 1                            ; <i32> [#uses=1]
     34 
     35 ; CHECK: %8 = sext i32 %7 to i64
     36 ; CHECK: -->  {1,+,2}<nuw><nsw><%bb>
     37   %8 = sext i32 %7 to i64                         ; <i64> [#uses=1]
     38 
     39 ; CHECK: %9 = getelementptr inbounds double* %q, i64 %8
     40 ; CHECK: {(8 + %q),+,16}<nsw><%bb>
     41   %9 = getelementptr inbounds double* %q, i64 %8  ; <double*> [#uses=1]
     42 
     43 ; Artificially repeat the above three instructions, this time using
     44 ; add nsw instead of or.
     45   %t7 = add nsw i32 %i.01, 1                            ; <i32> [#uses=1]
     46 
     47 ; CHECK: %t8 = sext i32 %t7 to i64
     48 ; CHECK: -->  {1,+,2}<nuw><nsw><%bb>
     49   %t8 = sext i32 %t7 to i64                         ; <i64> [#uses=1]
     50 
     51 ; CHECK: %t9 = getelementptr inbounds double* %q, i64 %t8
     52 ; CHECK: {(8 + %q),+,16}<nsw><%bb>
     53   %t9 = getelementptr inbounds double* %q, i64 %t8  ; <double*> [#uses=1]
     54 
     55   %10 = load double* %9, align 8                  ; <double> [#uses=1]
     56   %11 = fadd double %6, %10                       ; <double> [#uses=1]
     57   %12 = fadd double %11, 3.200000e+00             ; <double> [#uses=1]
     58   %13 = fmul double %3, %12                       ; <double> [#uses=1]
     59   %14 = sext i32 %i.01 to i64                     ; <i64> [#uses=1]
     60   %15 = getelementptr inbounds double* %d, i64 %14 ; <double*> [#uses=1]
     61   store double %13, double* %15, align 8
     62   %16 = add nsw i32 %i.01, 2                      ; <i32> [#uses=2]
     63   br label %bb1
     64 
     65 bb1:                                              ; preds = %bb
     66   %17 = icmp slt i32 %16, %n                      ; <i1> [#uses=1]
     67   br i1 %17, label %bb, label %bb1.return_crit_edge
     68 
     69 bb1.return_crit_edge:                             ; preds = %bb1
     70   br label %return
     71 
     72 return:                                           ; preds = %bb1.return_crit_edge, %entry
     73   ret void
     74 }
     75 
     76 ; CHECK: Loop %bb: backedge-taken count is ((-1 + (2 * (%no /u 2))) /u 2)
     77 ; CHECK: Loop %bb: max backedge-taken count is 1073741822
     78