diff options
author | Sanjay Patel <spatel@rotateright.com> | 2016-09-09 16:35:20 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2016-09-09 16:35:20 +0000 |
commit | 6da0fb8c74e16f26c4c96ab12a95975e3f1face7 (patch) | |
tree | abfbe711ecc11e15da7d22c8dfa795a509dfe0ed /llvm/test/Transforms/InstCombine/or.ll | |
parent | aa4adccc4dd2800aa15b5628a0ca77013c37ea53 (diff) | |
download | bcm5719-llvm-6da0fb8c74e16f26c4c96ab12a95975e3f1face7.tar.gz bcm5719-llvm-6da0fb8c74e16f26c4c96ab12a95975e3f1face7.zip |
[InstCombine] add tests to show pattern matching failures due to commutation
I was looking to fix a bug in getComplexity(), and these cases showed up as
obvious failures. I'm not sure how to find these in general though.
llvm-svn: 281055
Diffstat (limited to 'llvm/test/Transforms/InstCombine/or.ll')
-rw-r--r-- | llvm/test/Transforms/InstCombine/or.ll | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/or.ll b/llvm/test/Transforms/InstCombine/or.ll index 4fb1978615d..38b8ebc5adf 100644 --- a/llvm/test/Transforms/InstCombine/or.ll +++ b/llvm/test/Transforms/InstCombine/or.ll @@ -555,6 +555,8 @@ define i32 @test41(i32 %a, i32 %b) { ret i32 %or } +; (~A ^ B) | (A & B) -> (~A ^ B) + define i32 @test42(i32 %a, i32 %b) { ; CHECK-LABEL: @test42( ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 %a, -1 @@ -568,6 +570,42 @@ define i32 @test42(i32 %a, i32 %b) { ret i32 %or } +; FIXME: We miss the fold because the pattern matching is inadequate. + +define i32 @test42_commuted_and(i32 %a, i32 %b) { +; CHECK-LABEL: @test42_commuted_and( +; CHECK-NEXT: [[NEGA:%.*]] = xor i32 %a, -1 +; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[NEGA]], %b +; CHECK-NEXT: [[AND:%.*]] = and i32 %b, %a +; CHECK-NEXT: [[OR:%.*]] = or i32 [[XOR]], [[AND]] +; CHECK-NEXT: ret i32 [[OR]] +; + %nega = xor i32 %a, -1 + %xor = xor i32 %nega, %b + %and = and i32 %b, %a + %or = or i32 %xor, %and + ret i32 %or +} + +; FIXME: We miss the fold because the pattern matching is inadequate. + +define i32 @test42_commuted_xor(i32 %a, i32 %b) { +; CHECK-LABEL: @test42_commuted_xor( +; CHECK-NEXT: [[NEGA:%.*]] = xor i32 %a, -1 +; CHECK-NEXT: [[XOR:%.*]] = xor i32 %b, [[NEGA]] +; CHECK-NEXT: [[AND:%.*]] = and i32 %a, %b +; CHECK-NEXT: [[OR:%.*]] = or i32 [[XOR]], [[AND]] +; CHECK-NEXT: ret i32 [[OR]] +; + %nega = xor i32 %a, -1 + %xor = xor i32 %b, %nega + %and = and i32 %a, %b + %or = or i32 %xor, %and + ret i32 %or +} + +; Commute operands of the 'or'. + define i32 @test43(i32 %a, i32 %b) { ; CHECK-LABEL: @test43( ; CHECK-NEXT: [[OR:%.*]] = xor i32 %a, %b @@ -580,6 +618,23 @@ define i32 @test43(i32 %a, i32 %b) { ret i32 %or } +; FIXME: We miss the fold because the pattern matching is inadequate. + +define i32 @test43_commuted_and(i32 %a, i32 %b) { +; CHECK-LABEL: @test43_commuted_and( +; CHECK-NEXT: [[NEG:%.*]] = xor i32 %b, -1 +; CHECK-NEXT: [[AND:%.*]] = and i32 [[NEG]], %a +; CHECK-NEXT: [[XOR:%.*]] = xor i32 %a, %b +; CHECK-NEXT: [[OR:%.*]] = or i32 [[AND]], [[XOR]] +; CHECK-NEXT: ret i32 [[OR]] +; + %neg = xor i32 %b, -1 + %and = and i32 %neg, %a + %xor = xor i32 %a, %b + %or = or i32 %and, %xor + ret i32 %or +} + define i32 @test44(i32 %a, i32 %b) { ; CHECK-LABEL: @test44( ; CHECK-NEXT: [[OR:%.*]] = xor i32 %a, %b |