diff options
Diffstat (limited to 'test/Transforms/InstCombine/select-implied.ll')
| -rw-r--r-- | test/Transforms/InstCombine/select-implied.ll | 77 | 
1 files changed, 77 insertions, 0 deletions
diff --git a/test/Transforms/InstCombine/select-implied.ll b/test/Transforms/InstCombine/select-implied.ll index 2100e3eae0089..2558745c18f3c 100644 --- a/test/Transforms/InstCombine/select-implied.ll +++ b/test/Transforms/InstCombine/select-implied.ll @@ -121,3 +121,80 @@ end:  declare void @foo(i32)  declare i32 @bar(i32) + +; CHECK-LABEL: @test_and +; CHECK: tpath: +; CHECK-NOT: select +; CHECK: ret i32 313 +define i32 @test_and(i32 %a, i32 %b) { +entry: +  %cmp1 = icmp ne i32 %a, 0 +  %cmp2 = icmp ne i32 %b, 0 +  %and = and i1 %cmp1, %cmp2 +  br i1 %and, label %tpath, label %end + +tpath: +  %cmp3 = icmp eq i32 %a, 0 ;; <-- implied false +  %c = select i1 %cmp3, i32 0, i32 313 +  ret i32 %c + +end: +  ret i32 0 +} + +; cmp1 and cmp2 are false on the 'fpath' path and thus cmp3 is true. +; CHECK-LABEL: @test_or1 +; CHECK: fpath: +; CHECK-NOT: select +; CHECK: ret i32 37 +define i32 @test_or1(i32 %a, i32 %b) { +entry: +  %cmp1 = icmp eq i32 %a, 0 +  %cmp2 = icmp eq i32 %b, 0 +  %or = or i1 %cmp1, %cmp2 +  br i1 %or, label %end, label %fpath + +fpath: +  %cmp3 = icmp ne i32 %a, 0  ;; <-- implied true +  %c = select i1 %cmp3, i32 37, i32 0 +  ret i32 %c + +end: +  ret i32 0 +} + +; LHS ==> RHS by definition (true -> true) +; CHECK-LABEL: @test6 +; CHECK: taken: +; CHECK-NOT: select +; CHECK: call void @foo(i32 10) +define void @test6(i32 %a, i32 %b) { +  %cmp1 = icmp eq i32 %a, %b +  br i1 %cmp1, label %taken, label %end + +taken: +  %c = select i1 %cmp1, i32 10, i32 0 +  call void @foo(i32 %c) +  br label %end + +end: +  ret void +} + +; LHS ==> RHS by definition (false -> false) +; CHECK-LABEL: @test7 +; CHECK: taken: +; CHECK-NOT: select +; CHECK: call void @foo(i32 11) +define void @test7(i32 %a, i32 %b) { +  %cmp1 = icmp eq i32 %a, %b +  br i1 %cmp1, label %end, label %taken + +taken: +  %c = select i1 %cmp1, i32 0, i32 11 +  call void @foo(i32 %c) +  br label %end + +end: +  ret void +}  | 
