[llvm] r281055 - [InstCombine] add tests to show pattern matching failures due to commutation
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 9 09:35:20 PDT 2016
Author: spatel
Date: Fri Sep 9 11:35:20 2016
New Revision: 281055
URL: http://llvm.org/viewvc/llvm-project?rev=281055&view=rev
Log:
[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.
Modified:
llvm/trunk/test/Transforms/InstCombine/or-xor.ll
llvm/trunk/test/Transforms/InstCombine/or.ll
llvm/trunk/test/Transforms/InstCombine/xor2.ll
Modified: llvm/trunk/test/Transforms/InstCombine/or-xor.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/or-xor.ll?rev=281055&r1=281054&r2=281055&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/or-xor.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/or-xor.ll Fri Sep 9 11:35:20 2016
@@ -140,6 +140,23 @@ define i32 @test12(i32 %x, i32 %y) {
ret i32 %and
}
+; FIXME: We miss the fold because the pattern matching is inadequate.
+
+define i32 @test12_commuted(i32 %x, i32 %y) {
+; CHECK-LABEL: @test12_commuted(
+; CHECK-NEXT: [[NEG:%.*]] = xor i32 %x, -1
+; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[NEG]], %y
+; CHECK-NEXT: [[OR:%.*]] = or i32 %y, %x
+; CHECK-NEXT: [[AND:%.*]] = and i32 [[XOR]], [[OR]]
+; CHECK-NEXT: ret i32 [[AND]]
+;
+ %neg = xor i32 %x, -1
+ %xor = xor i32 %neg, %y
+ %or = or i32 %y, %x
+ %and = and i32 %xor, %or
+ ret i32 %and
+}
+
; ((x | y) ^ (x ^ y)) -> (x & y)
define i32 @test13(i32 %x, i32 %y) {
; CHECK-LABEL: @test13(
@@ -166,6 +183,25 @@ define i32 @test14(i32 %x, i32 %y) {
ret i32 %xor
}
+; FIXME: We miss the fold because the pattern matching is inadequate.
+
+define i32 @test14_commuted(i32 %x, i32 %y) {
+; CHECK-LABEL: @test14_commuted(
+; CHECK-NEXT: [[NOTY:%.*]] = xor i32 %y, -1
+; CHECK-NEXT: [[NOTX:%.*]] = xor i32 %x, -1
+; CHECK-NEXT: [[OR1:%.*]] = or i32 [[NOTY]], %x
+; CHECK-NEXT: [[OR2:%.*]] = or i32 [[NOTX]], %y
+; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[OR1]], [[OR2]]
+; CHECK-NEXT: ret i32 [[XOR]]
+;
+ %noty = xor i32 %y, -1
+ %notx = xor i32 %x, -1
+ %or1 = or i32 %noty, %x
+ %or2 = or i32 %notx, %y
+ %xor = xor i32 %or1, %or2
+ ret i32 %xor
+}
+
; ((x & ~y) ^ (~x & y)) -> x ^ y
define i32 @test15(i32 %x, i32 %y) {
; CHECK-LABEL: @test15(
@@ -178,6 +214,25 @@ define i32 @test15(i32 %x, i32 %y) {
%and2 = and i32 %notx, %y
%xor = xor i32 %and1, %and2
ret i32 %xor
+}
+
+; FIXME: We miss the fold because the pattern matching is inadequate.
+
+define i32 @test15_commuted(i32 %x, i32 %y) {
+; CHECK-LABEL: @test15_commuted(
+; CHECK-NEXT: [[NOTY:%.*]] = xor i32 %y, -1
+; CHECK-NEXT: [[NOTX:%.*]] = xor i32 %x, -1
+; CHECK-NEXT: [[AND1:%.*]] = and i32 [[NOTY]], %x
+; CHECK-NEXT: [[AND2:%.*]] = and i32 [[NOTX]], %y
+; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[AND1]], [[AND2]]
+; CHECK-NEXT: ret i32 [[XOR]]
+;
+ %noty = xor i32 %y, -1
+ %notx = xor i32 %x, -1
+ %and1 = and i32 %noty, %x
+ %and2 = and i32 %notx, %y
+ %xor = xor i32 %and1, %and2
+ ret i32 %xor
}
define i32 @test16(i32 %a, i32 %b) {
Modified: llvm/trunk/test/Transforms/InstCombine/or.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/or.ll?rev=281055&r1=281054&r2=281055&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/or.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/or.ll Fri Sep 9 11:35:20 2016
@@ -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
@@ -578,6 +616,23 @@ define i32 @test43(i32 %a, i32 %b) {
%xor = xor i32 %a, %b
%or = or i32 %and, %xor
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) {
Modified: llvm/trunk/test/Transforms/InstCombine/xor2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/xor2.ll?rev=281055&r1=281054&r2=281055&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/xor2.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/xor2.ll Fri Sep 9 11:35:20 2016
@@ -180,6 +180,27 @@ define i32 @test12(i32 %a, i32 %b) {
ret i32 %xor
}
+; FIXME: We miss the fold because the pattern matching is inadequate.
+
+define i32 @test12commuted(i32 %a, i32 %b) {
+; CHECK-LABEL: @test12commuted(
+; CHECK-NEXT: [[NEGB:%.*]] = xor i32 %b, -1
+; CHECK-NEXT: [[AND:%.*]] = and i32 [[NEGB]], %a
+; CHECK-NEXT: [[NEGA:%.*]] = xor i32 %a, -1
+; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[AND]], [[NEGA]]
+; CHECK-NEXT: ret i32 [[XOR]]
+;
+ %negb = xor i32 %b, -1
+ %and = and i32 %negb, %a
+ %nega = xor i32 %a, -1
+ %xor = xor i32 %and, %nega
+ ret i32 %xor
+}
+
+; This is a test of canonicalization via operand complexity.
+; The final xor has a binary operator and a (fake) unary operator,
+; so binary (more complex) should come first.
+
define i32 @test13(i32 %a, i32 %b) {
; CHECK-LABEL: @test13(
; CHECK-NEXT: [[TMP1:%.*]] = and i32 %a, %b
@@ -192,6 +213,23 @@ define i32 @test13(i32 %a, i32 %b) {
%xor = xor i32 %nega, %and
ret i32 %xor
}
+
+; FIXME: We miss the fold because the pattern matching is inadequate.
+
+define i32 @test13commuted(i32 %a, i32 %b) {
+; CHECK-LABEL: @test13commuted(
+; CHECK-NEXT: [[NEGA:%.*]] = xor i32 %a, -1
+; CHECK-NEXT: [[NEGB:%.*]] = xor i32 %b, -1
+; CHECK-NEXT: [[AND:%.*]] = and i32 [[NEGB]], %a
+; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[AND]], [[NEGA]]
+; CHECK-NEXT: ret i32 [[XOR]]
+;
+ %nega = xor i32 %a, -1
+ %negb = xor i32 %b, -1
+ %and = and i32 %negb, %a
+ %xor = xor i32 %nega, %and
+ ret i32 %xor
+}
; (A ^ C) ^ (A | B) -> ((~A) & B) ^ C
define i32 @test14(i32 %a, i32 %b, i32 %c) {
More information about the llvm-commits
mailing list