Home | History | Annotate | Download | only in LoopAccessAnalysis
      1 ; RUN: opt < %s -loop-accesses -analyze | FileCheck %s
      2 
      3 ; Test to confirm LAA will find store to invariant address.
      4 ; Inner loop has a store to invariant address.
      5 ;
      6 ;  for(; i < itr; i++) {
      7 ;    for(; j < itr; j++) {
      8 ;      var1[i] = var2[j] + var1[i];
      9 ;    }
     10 ;  }
     11 
     12 ; CHECK: Store to invariant address was found in loop.
     13 ; CHECK-NOT: Store to invariant address was not found in loop.
     14 
     15 define i32 @foo(i32* nocapture %var1, i32* nocapture readonly %var2, i32 %itr) #0 {
     16 entry:
     17   %cmp20 = icmp eq i32 %itr, 0
     18   br i1 %cmp20, label %for.end10, label %for.cond1.preheader
     19 
     20 for.cond1.preheader:                              ; preds = %entry, %for.inc8
     21   %indvars.iv23 = phi i64 [ %indvars.iv.next24, %for.inc8 ], [ 0, %entry ]
     22   %j.022 = phi i32 [ %j.1.lcssa, %for.inc8 ], [ 0, %entry ]
     23   %cmp218 = icmp ult i32 %j.022, %itr
     24   br i1 %cmp218, label %for.body3.lr.ph, label %for.inc8
     25 
     26 for.body3.lr.ph:                                  ; preds = %for.cond1.preheader
     27   %arrayidx5 = getelementptr inbounds i32, i32* %var1, i64 %indvars.iv23
     28   %0 = zext i32 %j.022 to i64
     29   br label %for.body3
     30 
     31 for.body3:                                        ; preds = %for.body3, %for.body3.lr.ph
     32   %indvars.iv = phi i64 [ %0, %for.body3.lr.ph ], [ %indvars.iv.next, %for.body3 ]
     33   %arrayidx = getelementptr inbounds i32, i32* %var2, i64 %indvars.iv
     34   %1 = load i32, i32* %arrayidx, align 4
     35   %2 = load i32, i32* %arrayidx5, align 4
     36   %add = add nsw i32 %2, %1
     37   store i32 %add, i32* %arrayidx5, align 4
     38   %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
     39   %lftr.wideiv = trunc i64 %indvars.iv.next to i32
     40   %exitcond = icmp eq i32 %lftr.wideiv, %itr
     41   br i1 %exitcond, label %for.inc8, label %for.body3
     42 
     43 for.inc8:                                         ; preds = %for.body3, %for.cond1.preheader
     44   %j.1.lcssa = phi i32 [ %j.022, %for.cond1.preheader ], [ %itr, %for.body3 ]
     45   %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
     46   %lftr.wideiv25 = trunc i64 %indvars.iv.next24 to i32
     47   %exitcond26 = icmp eq i32 %lftr.wideiv25, %itr
     48   br i1 %exitcond26, label %for.end10, label %for.cond1.preheader
     49 
     50 for.end10:                                        ; preds = %for.inc8, %entry
     51   ret i32 undef
     52 }
     53 
     54