Home | History | Annotate | Download | only in GVN
      1 ; RUN: opt -basicaa -gvn -S < %s | FileCheck %s
      2 
      3 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-n8:16:32:64"
      4 target triple = "x86_64-apple-macosx10.7.0"
      5 
      6 @x = common global i32 0, align 4
      7 @y = common global i32 0, align 4
      8 
      9 ; GVN across unordered store (allowed)
     10 define i32 @test1() nounwind uwtable ssp {
     11 ; CHECK-LABEL: test1
     12 ; CHECK: add i32 %x, %x
     13 entry:
     14   %x = load i32, i32* @y
     15   store atomic i32 %x, i32* @x unordered, align 4
     16   %y = load i32, i32* @y
     17   %z = add i32 %x, %y
     18   ret i32 %z
     19 }
     20 
     21 ; GVN across unordered load (allowed)
     22 define i32 @test3() nounwind uwtable ssp {
     23 ; CHECK-LABEL: test3
     24 ; CHECK: add i32 %x, %x
     25 entry:
     26   %x = load i32, i32* @y
     27   %y = load atomic i32, i32* @x unordered, align 4
     28   %z = load i32, i32* @y
     29   %a = add i32 %x, %z
     30   %b = add i32 %y, %a
     31   ret i32 %b
     32 }
     33 
     34 ; GVN load to unordered load (allowed)
     35 define i32 @test5() nounwind uwtable ssp {
     36 ; CHECK-LABEL: test5
     37 ; CHECK: add i32 %x, %x
     38 entry:
     39   %x = load atomic i32, i32* @x unordered, align 4
     40   %y = load i32, i32* @x
     41   %z = add i32 %x, %y
     42   ret i32 %z
     43 }
     44 
     45 ; GVN unordered load to load (unordered load must not be removed)
     46 define i32 @test6() nounwind uwtable ssp {
     47 ; CHECK-LABEL: test6
     48 ; CHECK: load atomic i32, i32* @x unordered
     49 entry:
     50   %x = load i32, i32* @x
     51   %x2 = load atomic i32, i32* @x unordered, align 4
     52   %x3 = add i32 %x, %x2
     53   ret i32 %x3
     54 }
     55 
     56 ; GVN across release-acquire pair (forbidden)
     57 define i32 @test7() nounwind uwtable ssp {
     58 ; CHECK-LABEL: test7
     59 ; CHECK: add i32 %x, %y
     60 entry:
     61   %x = load i32, i32* @y
     62   store atomic i32 %x, i32* @x release, align 4
     63   %w = load atomic i32, i32* @x acquire, align 4
     64   %y = load i32, i32* @y
     65   %z = add i32 %x, %y
     66   ret i32 %z
     67 }
     68 
     69 ; GVN across monotonic store (allowed)
     70 define i32 @test9() nounwind uwtable ssp {
     71 ; CHECK-LABEL: test9
     72 ; CHECK: add i32 %x, %x
     73 entry:
     74   %x = load i32, i32* @y
     75   store atomic i32 %x, i32* @x monotonic, align 4
     76   %y = load i32, i32* @y
     77   %z = add i32 %x, %y
     78   ret i32 %z
     79 }
     80 
     81 ; GVN of an unordered across monotonic load (not allowed)
     82 define i32 @test10() nounwind uwtable ssp {
     83 ; CHECK-LABEL: test10
     84 ; CHECK: add i32 %x, %y
     85 entry:
     86   %x = load atomic i32, i32* @y unordered, align 4
     87   %clobber = load atomic i32, i32* @x monotonic, align 4
     88   %y = load atomic i32, i32* @y monotonic, align 4
     89   %z = add i32 %x, %y
     90   ret i32 %z
     91 }
     92 
     93 define i32 @PR22708(i1 %flag) {
     94 ; CHECK-LABEL: PR22708
     95 entry:
     96   br i1 %flag, label %if.then, label %if.end
     97 
     98 if.then:
     99   store i32 43, i32* @y, align 4
    100 ; CHECK: store i32 43, i32* @y, align 4
    101   br label %if.end
    102 
    103 if.end:
    104   load atomic i32, i32* @x acquire, align 4
    105   %load = load i32, i32* @y, align 4
    106 ; CHECK: load atomic i32, i32* @x acquire, align 4
    107 ; CHECK: load i32, i32* @y, align 4
    108   ret i32 %load
    109 }
    110