Home | History | Annotate | Download | only in InstCombine
      1 ; RUN: opt < %s -instcombine -S | FileCheck %s
      2 ; These should be InstSimplify checks, but most of the code
      3 ; is currently only in InstCombine.  TODO: move supporting code
      4 
      5 ; Definitely out of range
      6 define i1 @test_nonzero(i32* nocapture readonly %arg) {
      7 ; CHECK-LABEL:test_nonzero
      8 ; CHECK: ret i1 true
      9   %val = load i32, i32* %arg, !range !0
     10   %rval = icmp ne i32 %val, 0
     11   ret i1 %rval
     12 }
     13 define i1 @test_nonzero2(i32* nocapture readonly %arg) {
     14 ; CHECK-LABEL:test_nonzero2
     15 ; CHECK: ret i1 false
     16   %val = load i32, i32* %arg, !range !0
     17   %rval = icmp eq i32 %val, 0
     18   ret i1 %rval
     19 }
     20 
     21 ; Potentially in range
     22 define i1 @test_nonzero3(i32* nocapture readonly %arg) {
     23 ; CHECK-LABEL: test_nonzero3
     24 ; Check that this does not trigger - it wouldn't be legal
     25 ; CHECK: icmp
     26   %val = load i32, i32* %arg, !range !1
     27   %rval = icmp ne i32 %val, 0
     28   ret i1 %rval
     29 }
     30 
     31 ; Definitely in range
     32 define i1 @test_nonzero4(i8* nocapture readonly %arg) {
     33 ; CHECK-LABEL: test_nonzero4
     34 ; CHECK: ret i1 false
     35   %val = load i8, i8* %arg, !range !2
     36   %rval = icmp ne i8 %val, 0
     37   ret i1 %rval
     38 }
     39 
     40 define i1 @test_nonzero5(i8* nocapture readonly %arg) {
     41 ; CHECK-LABEL: test_nonzero5
     42 ; CHECK: ret i1 false
     43   %val = load i8, i8* %arg, !range !2
     44   %rval = icmp ugt i8 %val, 0
     45   ret i1 %rval
     46 }
     47 
     48 ; Cheaper checks (most values in range meet requirements)
     49 define i1 @test_nonzero6(i8* %argw) {
     50 ; CHECK-LABEL: test_nonzero6
     51 ; CHECK: icmp ne i8 %val, 0
     52   %val = load i8, i8* %argw, !range !3
     53   %rval = icmp sgt i8 %val, 0
     54   ret i1 %rval
     55 }
     56 
     57 
     58 !0 = !{i32 1, i32 6} 
     59 !1 = !{i32 0, i32 6} 
     60 !2 = !{i8 0, i8 1} 
     61 !3 = !{i8 0, i8 6} 
     62