summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/InstCombine/and2.ll
diff options
context:
space:
mode:
authorBalaram Makam <bmakam@codeaurora.org>2015-08-20 15:35:00 +0000
committerBalaram Makam <bmakam@codeaurora.org>2015-08-20 15:35:00 +0000
commitccf59731e3b7d4920c04339c600ec67af648a9d0 (patch)
treee905ce1b4789ece1f787c677071e092b51dfa026 /llvm/test/Transforms/InstCombine/and2.ll
parentae6b329c8fcffbd437624111b430e10ad57a7627 (diff)
downloadbcm5719-llvm-ccf59731e3b7d4920c04339c600ec67af648a9d0.tar.gz
bcm5719-llvm-ccf59731e3b7d4920c04339c600ec67af648a9d0.zip
Optimize bitwise even/odd test (-x&1 -> x&1) to not use negation.
Summary: We know that -x & 1 is equivalent to x & 1, avoid using negation for testing if a negative integer is even or odd. Reviewers: majnemer Subscribers: junbuml, mssimpso, gberry, mcrosier, llvm-commits Differential Revision: http://reviews.llvm.org/D12156 llvm-svn: 245569
Diffstat (limited to 'llvm/test/Transforms/InstCombine/and2.ll')
-rw-r--r--llvm/test/Transforms/InstCombine/and2.ll25
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/and2.ll b/llvm/test/Transforms/InstCombine/and2.ll
index 96b535dda99..9be6b58979d 100644
--- a/llvm/test/Transforms/InstCombine/and2.ll
+++ b/llvm/test/Transforms/InstCombine/and2.ll
@@ -77,3 +77,28 @@ define i1 @test8(i32 %i) {
%cond = and i1 %cmp1, %cmp2
ret i1 %cond
}
+
+; combine -x & 1 into x & 1
+define i64 @test9(i64 %x) {
+; CHECK-LABEL: @test9(
+; CHECK-NOT: %sub = sub nsw i64 0, %x
+; CHECK-NOT: %and = and i64 %sub, 1
+; CHECK-NEXT: %and = and i64 %x, 1
+; CHECK-NEXT: ret i64 %and
+ %sub = sub nsw i64 0, %x
+ %and = and i64 %sub, 1
+ ret i64 %and
+}
+
+define i64 @test10(i64 %x) {
+; CHECK-LABEL: @test10(
+; CHECK-NOT: %sub = sub nsw i64 0, %x
+; CHECK-NEXT: %and = and i64 %x, 1
+; CHECK-NOT: %add = add i64 %sub, %and
+; CHECK-NEXT: %add = sub i64 %and, %x
+; CHECK-NEXT: ret i64 %add
+ %sub = sub nsw i64 0, %x
+ %and = and i64 %sub, 1
+ %add = add i64 %sub, %and
+ ret i64 %add
+}
OpenPOWER on IntegriCloud