summaryrefslogtreecommitdiffstats
path: root/llvm/test
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-07-30 21:26:37 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-07-30 21:26:37 +0000
commit42af3601c29a521cec564c2c55e43f9751494b8e (patch)
treefeffa04ccfa985f458c4cd71aff9389119c8efcb /llvm/test
parent2aa09d4319ff20528806bbb85844559b22347294 (diff)
downloadbcm5719-llvm-42af3601c29a521cec564c2c55e43f9751494b8e.tar.gz
bcm5719-llvm-42af3601c29a521cec564c2c55e43f9751494b8e.zip
InstCombine: Simplify (A ^ B) or/and (A ^ B ^ C)
While we can already transform A | (A ^ B) into A | B, things get bad once we have (A ^ B) | (A ^ B ^ Cst) because reassociation will morph this into (A ^ B) | ((A ^ Cst) ^ B). Our existing patterns fail once this happens. To fix this, we add a new pattern which looks through the tree of xor binary operators to see that, in fact, there exists a redundant xor operation. What follows bellow is a correctness proof of the transform using CVC3. $ cat t.cvc A, B, C : BITVECTOR(64); QUERY BVXOR(A, B) | BVXOR(BVXOR(B, C), A) = BVXOR(A, B) | C; QUERY BVXOR(BVXOR(A, C), B) | BVXOR(A, B) = BVXOR(A, B) | C; QUERY BVXOR(A, B) & BVXOR(BVXOR(B, C), A) = BVXOR(A, B) & ~C; QUERY BVXOR(BVXOR(A, C), B) & BVXOR(A, B) = BVXOR(A, B) & ~C; $ cvc3 < t.cvc Valid. Valid. Valid. Valid. llvm-svn: 214342
Diffstat (limited to 'llvm/test')
-rw-r--r--llvm/test/Transforms/InstCombine/or-xor.ll20
-rw-r--r--llvm/test/Transforms/InstCombine/xor2.ll20
2 files changed, 40 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/or-xor.ll b/llvm/test/Transforms/InstCombine/or-xor.ll
index cec36f119a9..3f247e27522 100644
--- a/llvm/test/Transforms/InstCombine/or-xor.ll
+++ b/llvm/test/Transforms/InstCombine/or-xor.ll
@@ -92,3 +92,23 @@ define i32 @test9(i32 %x, i32 %y) nounwind {
; CHECK-NEXT: %z = or i32 %y.not, %x
; CHECK-NEXT: ret i32 %z
}
+
+define i32 @test10(i32 %A, i32 %B) {
+ %xor1 = xor i32 %B, %A
+ %not = xor i32 %A, -1
+ %xor2 = xor i32 %not, %B
+ %or = or i32 %xor1, %xor2
+ ret i32 %or
+; CHECK-LABEL: @test10(
+; CHECK-NEXT: ret i32 -1
+}
+
+define i32 @test11(i32 %A, i32 %B) {
+ %xor1 = xor i32 %B, %A
+ %not = xor i32 %A, -1
+ %xor2 = xor i32 %not, %B
+ %or = or i32 %xor1, %xor2
+ ret i32 %or
+; CHECK-LABEL: @test11(
+; CHECK-NEXT: ret i32 -1
+}
diff --git a/llvm/test/Transforms/InstCombine/xor2.ll b/llvm/test/Transforms/InstCombine/xor2.ll
index 4ae50a140e1..6318afe51bf 100644
--- a/llvm/test/Transforms/InstCombine/xor2.ll
+++ b/llvm/test/Transforms/InstCombine/xor2.ll
@@ -125,3 +125,23 @@ define i32 @test10(i32 %b, i32 %c) {
; CHECK-LABEL: @test10(
; CHECK-NEXT: %xor2 = or i32 %b, %c
}
+
+define i32 @test11(i32 %A, i32 %B) {
+ %xor1 = xor i32 %B, %A
+ %not = xor i32 %A, -1
+ %xor2 = xor i32 %not, %B
+ %and = and i32 %xor1, %xor2
+ ret i32 %and
+; CHECK-LABEL: @test11(
+; CHECK-NEXT: ret i32 0
+}
+
+define i32 @test12(i32 %A, i32 %B) {
+ %xor1 = xor i32 %B, %A
+ %not = xor i32 %A, -1
+ %xor2 = xor i32 %not, %B
+ %and = and i32 %xor1, %xor2
+ ret i32 %and
+; CHECK-LABEL: @test12(
+; CHECK-NEXT: ret i32 0
+}
OpenPOWER on IntegriCloud