diff options
author | Tim Northover <tnorthover@apple.com> | 2013-09-04 11:57:13 +0000 |
---|---|---|
committer | Tim Northover <tnorthover@apple.com> | 2013-09-04 11:57:13 +0000 |
commit | 7bfabdac4ebf82f9f6a9ee7a00fd948f729dc7fe (patch) | |
tree | 1b055e115a9e2cdf1d252c94d510aaa6ba2b005f /test/Transforms/InstCombine | |
parent | 19fdc268c316b3b0bdcb2b558449819f4f402d6a (diff) | |
download | external_llvm-7bfabdac4ebf82f9f6a9ee7a00fd948f729dc7fe.zip external_llvm-7bfabdac4ebf82f9f6a9ee7a00fd948f729dc7fe.tar.gz external_llvm-7bfabdac4ebf82f9f6a9ee7a00fd948f729dc7fe.tar.bz2 |
InstCombine: look for masked compares with subset relation
Even in cases which aren't universally optimisable like "(A & B) != 0 && (A &
C) != 0", the masks can make one of the comparisons completely redundant. In
this case, since we've gone to the effort of spotting masked comparisons we
should combine them.
rdar://problem/7625728
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189930 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/InstCombine')
-rw-r--r-- | test/Transforms/InstCombine/icmp-logical.ll | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/test/Transforms/InstCombine/icmp-logical.ll b/test/Transforms/InstCombine/icmp-logical.ll new file mode 100644 index 0000000..c0c5a61 --- /dev/null +++ b/test/Transforms/InstCombine/icmp-logical.ll @@ -0,0 +1,122 @@ +; RUN: opt -instcombine -S -o - %s | FileCheck %s + +define i1 @masked_and_notallzeroes(i32 %A) { +; CHECK-LABEL: @masked_and_notallzeroes +; CHECK: [[MASK:%.*]] = and i32 %A, 7 +; CHECK: icmp ne i32 [[MASK]], 0 +; CHECK-NOT: and i32 %A, 39 +; CHECK: ret i1 + + %mask1 = and i32 %A, 7 + %tst1 = icmp ne i32 %mask1, 0 + + %mask2 = and i32 %A, 39 + %tst2 = icmp ne i32 %mask2, 0 + + %res = and i1 %tst1, %tst2 + ret i1 %res +} + +define i1 @masked_or_allzeroes(i32 %A) { +; CHECK-LABEL: @masked_or_allzeroes +; CHECK: [[MASK:%.*]] = and i32 %A, 7 +; CHECK: icmp eq i32 [[MASK]], 0 +; CHECK-NOT: and i32 %A, 39 +; CHECK: ret i1 + + %mask1 = and i32 %A, 7 + %tst1 = icmp eq i32 %mask1, 0 + + %mask2 = and i32 %A, 39 + %tst2 = icmp eq i32 %mask2, 0 + + %res = or i1 %tst1, %tst2 + ret i1 %res +} + +define i1 @masked_and_notallones(i32 %A) { +; CHECK-LABEL: @masked_and_notallones +; CHECK: [[MASK:%.*]] = and i32 %A, 7 +; CHECK: icmp ne i32 [[MASK]], 7 +; CHECK-NOT: and i32 %A, 39 +; CHECK: ret i1 + + %mask1 = and i32 %A, 7 + %tst1 = icmp ne i32 %mask1, 7 + + %mask2 = and i32 %A, 39 + %tst2 = icmp ne i32 %mask2, 39 + + %res = and i1 %tst1, %tst2 + ret i1 %res +} + +define i1 @masked_or_allones(i32 %A) { +; CHECK-LABEL: @masked_or_allones +; CHECK: [[MASK:%.*]] = and i32 %A, 7 +; CHECK: icmp eq i32 [[MASK]], 7 +; CHECK-NOT: and i32 %A, 39 +; CHECK: ret i1 + + %mask1 = and i32 %A, 7 + %tst1 = icmp eq i32 %mask1, 7 + + %mask2 = and i32 %A, 39 + %tst2 = icmp eq i32 %mask2, 39 + + %res = or i1 %tst1, %tst2 + ret i1 %res +} + +define i1 @masked_and_notA(i32 %A) { +; CHECK-LABEL: @masked_and_notA +; CHECK: [[MASK:%.*]] = and i32 %A, 39 +; CHECK: icmp ne i32 [[MASK]], %A +; CHECK-NOT: and i32 %A, 7 +; CHECK: ret i1 + + %mask1 = and i32 %A, 7 + %tst1 = icmp ne i32 %mask1, %A + + %mask2 = and i32 %A, 39 + %tst2 = icmp ne i32 %mask2, %A + + %res = and i1 %tst1, %tst2 + ret i1 %res +} + +define i1 @masked_or_A(i32 %A) { +; CHECK-LABEL: @masked_or_A +; CHECK: [[MASK:%.*]] = and i32 %A, 39 +; CHECK: icmp eq i32 [[MASK]], %A +; CHECK-NOT: and i32 %A, 7 +; CHECK: ret i1 + + %mask1 = and i32 %A, 7 + %tst1 = icmp eq i32 %mask1, %A + + %mask2 = and i32 %A, 39 + %tst2 = icmp eq i32 %mask2, %A + + %res = or i1 %tst1, %tst2 + ret i1 %res +} + +define i1 @masked_or_allzeroes_notoptimised(i32 %A) { +; CHECK-LABEL: @masked_or_allzeroes_notoptimised +; CHECK: [[MASK:%.*]] = and i32 %A, 15 +; CHECK: icmp eq i32 [[MASK]], 0 +; CHECK: [[MASK:%.*]] = and i32 %A, 39 +; CHECK: icmp eq i32 [[MASK]], 0 +; CHECK: ret i1 + + %mask1 = and i32 %A, 15 + %tst1 = icmp eq i32 %mask1, 0 + + %mask2 = and i32 %A, 39 + %tst2 = icmp eq i32 %mask2, 0 + + %res = or i1 %tst1, %tst2 + ret i1 %res +} + |