Home | History | Annotate | Download | only in GVNHoist
      1 ; RUN: opt -S -gvn-hoist < %s | FileCheck %s
      2 
      3 ; Check that the stores are not hoisted: it is invalid to hoist stores if they
      4 ; are not executed on all paths. In this testcase, there are paths in the loop
      5 ; that do not execute the stores.
      6 
      7 ; CHECK-LABEL: define i32 @main
      8 ; CHECK: store
      9 ; CHECK: store
     10 ; CHECK: store
     11 
     12 @a = global i32 0, align 4
     13 
     14 define i32 @main() {
     15 entry:
     16   br label %for.cond
     17 
     18 for.cond:                                         ; preds = %for.inc5, %entry
     19   %0 = load i32, i32* @a, align 4
     20   %cmp = icmp slt i32 %0, 1
     21   br i1 %cmp, label %for.cond1, label %for.end7
     22 
     23 for.cond1:                                        ; preds = %for.cond, %for.inc
     24   %1 = load i32, i32* @a, align 4
     25   %cmp2 = icmp slt i32 %1, 1
     26   br i1 %cmp2, label %for.body3, label %for.inc5
     27 
     28 for.body3:                                        ; preds = %for.cond1
     29   %tobool = icmp ne i32 %1, 0
     30   br i1 %tobool, label %if.then, label %for.inc
     31 
     32 if.then:                                          ; preds = %for.body3
     33   %inc = add nsw i32 %1, 1
     34   store i32 %inc, i32* @a, align 4
     35   br label %for.inc
     36 
     37 for.inc:                                          ; preds = %for.body3, %if.then
     38   %2 = load i32, i32* @a, align 4
     39   %inc4 = add nsw i32 %2, 1
     40   store i32 %inc4, i32* @a, align 4
     41   br label %for.cond1
     42 
     43 for.inc5:                                         ; preds = %for.cond1
     44   %inc6 = add nsw i32 %1, 1
     45   store i32 %inc6, i32* @a, align 4
     46   br label %for.cond
     47 
     48 for.end7:                                         ; preds = %for.cond
     49   ret i32 %0
     50 }
     51 
     52