From dfb806f6ba53b792171b928b57def9d0182d2f5f Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sun, 8 Jan 2012 18:32:24 +0000 Subject: InstCombine: If we have a bit test and a sign test anded/ored together, merge the sign bit into the bit test. This is common in bit field code, e.g. checking if the first or the last bit of a bit field is set. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147749 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Transforms/InstCombine/sign-test-and-or.ll | 80 +++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'test/Transforms/InstCombine/sign-test-and-or.ll') diff --git a/test/Transforms/InstCombine/sign-test-and-or.ll b/test/Transforms/InstCombine/sign-test-and-or.ll index 47f5f3051e..2a5f772506 100644 --- a/test/Transforms/InstCombine/sign-test-and-or.ll +++ b/test/Transforms/InstCombine/sign-test-and-or.ll @@ -77,3 +77,83 @@ if.then: if.end: ret void } + +define void @test5(i32 %a) nounwind { + %and = and i32 %a, 134217728 + %1 = icmp eq i32 %and, 0 + %2 = icmp sgt i32 %a, -1 + %or.cond = and i1 %1, %2 + br i1 %or.cond, label %if.then, label %if.end + +; CHECK: @test5 +; CHECK-NEXT: %and = and i32 %a, -2013265920 +; CHECK-NEXT: %1 = icmp eq i32 %and, 0 +; CHECK-NEXT: br i1 %1, label %if.then, label %if.end + +if.then: + tail call void @foo() nounwind + ret void + +if.end: + ret void +} + +define void @test6(i32 %a) nounwind { + %1 = icmp sgt i32 %a, -1 + %and = and i32 %a, 134217728 + %2 = icmp eq i32 %and, 0 + %or.cond = and i1 %1, %2 + br i1 %or.cond, label %if.then, label %if.end + +; CHECK: @test6 +; CHECK-NEXT: %and = and i32 %a, -2013265920 +; CHECK-NEXT: %1 = icmp eq i32 %and, 0 +; CHECK-NEXT: br i1 %1, label %if.then, label %if.end + +if.then: + tail call void @foo() nounwind + ret void + +if.end: + ret void +} + +define void @test7(i32 %a) nounwind { + %and = and i32 %a, 134217728 + %1 = icmp ne i32 %and, 0 + %2 = icmp slt i32 %a, 0 + %or.cond = or i1 %1, %2 + br i1 %or.cond, label %if.then, label %if.end + +; CHECK: @test7 +; CHECK-NEXT: %and = and i32 %a, -2013265920 +; CHECK-NEXT: %1 = icmp eq i32 %and, 0 +; CHECK-NEXT: br i1 %1, label %if.end, label %if.the + +if.then: + tail call void @foo() nounwind + ret void + +if.end: + ret void +} + +define void @test8(i32 %a) nounwind { + %1 = icmp slt i32 %a, 0 + %and = and i32 %a, 134217728 + %2 = icmp ne i32 %and, 0 + %or.cond = or i1 %1, %2 + br i1 %or.cond, label %if.then, label %if.end + +; CHECK: @test8 +; CHECK-NEXT: %and = and i32 %a, -2013265920 +; CHECK-NEXT: %1 = icmp eq i32 %and, 0 +; CHECK-NEXT: br i1 %1, label %if.end, label %if.the + +if.then: + tail call void @foo() nounwind + ret void + +if.end: + ret void +} -- cgit v1.2.3