[llvm] r304021 - [InstSimplify] Use m_APInt instead of m_ConstantInt in ((V + N) & C1) | (V & C2) handling in order to support splat vectors.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Fri May 26 12:03:53 PDT 2017
Author: ctopper
Date: Fri May 26 14:03:53 2017
New Revision: 304021
URL: http://llvm.org/viewvc/llvm-project?rev=304021&view=rev
Log:
[InstSimplify] Use m_APInt instead of m_ConstantInt in ((V + N) & C1) | (V & C2) handling in order to support splat vectors.
The tests here are have operands commuted to provide more coverage. I also commuted one of the instructions in the scalar tests so the 4 tests cover the 4 commuted variations
Differential Revision: https://reviews.llvm.org/D33599
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/or.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=304021&r1=304020&r2=304021&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Fri May 26 14:03:53 2017
@@ -1922,34 +1922,34 @@ static Value *SimplifyOrInst(Value *Op0,
return V;
// (A & C1)|(B & C2)
- ConstantInt *C1, *C2;
- if (match(Op0, m_And(m_Value(A), m_ConstantInt(C1))) &&
- match(Op1, m_And(m_Value(B), m_ConstantInt(C2)))) {
- if (C1->getValue() == ~C2->getValue()) {
+ const APInt *C1, *C2;
+ if (match(Op0, m_And(m_Value(A), m_APInt(C1))) &&
+ match(Op1, m_And(m_Value(B), m_APInt(C2)))) {
+ if (*C1 == ~*C2) {
// (A & C1)|(B & C2)
// If we have: ((V + N) & C1) | (V & C2)
// .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
// replace with V+N.
Value *V1, *V2;
- if (C2->getValue().isMask() && // C2 == 0+1+
+ if (C2->isMask() && // C2 == 0+1+
match(A, m_Add(m_Value(V1), m_Value(V2)))) {
// Add commutes, try both ways.
if (V1 == B &&
- MaskedValueIsZero(V2, C2->getValue(), Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
+ MaskedValueIsZero(V2, *C2, Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
return A;
if (V2 == B &&
- MaskedValueIsZero(V1, C2->getValue(), Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
+ MaskedValueIsZero(V1, *C2, Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
return A;
}
// Or commutes, try both ways.
- if (C1->getValue().isMask() &&
+ if (C1->isMask() &&
match(B, m_Add(m_Value(V1), m_Value(V2)))) {
// Add commutes, try both ways.
if (V1 == A &&
- MaskedValueIsZero(V2, C1->getValue(), Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
+ MaskedValueIsZero(V2, *C1, Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
return B;
if (V2 == A &&
- MaskedValueIsZero(V1, C1->getValue(), Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
+ MaskedValueIsZero(V1, *C1, Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
return B;
}
}
Modified: llvm/trunk/test/Transforms/InstSimplify/or.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/or.ll?rev=304021&r1=304020&r2=304021&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/or.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/or.ll Fri May 26 14:03:53 2017
@@ -159,7 +159,7 @@ define i399 @test4_apint(i399 %V, i399 %
%A = add i399 %V, %N
%B = and i399 %A, %C1
%D = and i399 %V, 274877906943
- %R = or i399 %B, %D
+ %R = or i399 %D, %B
ret i399 %R
}
@@ -179,3 +179,42 @@ define i117 @test6_apint(i117 %X) {
ret i117 %Y
}
+; Test the case where integer BitWidth <= 64 && BitWidth % 2 != 0.
+; Vector version of test1_apint with the add commuted
+define <2 x i39> @test7_apint(<2 x i39> %V, <2 x i39> %M) {
+; CHECK-LABEL: @test7_apint(
+; CHECK-NEXT: [[N:%.*]] = and <2 x i39> [[M:%.*]], <i39 -274877906944, i39 -274877906944>
+; CHECK-NEXT: [[A:%.*]] = add <2 x i39> [[N]], [[V:%.*]]
+; CHECK-NEXT: ret <2 x i39> [[A]]
+;
+ ;; If we have: ((V + N) & C1) | (V & C2)
+ ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
+ ;; replace with V+N.
+ %C1 = xor <2 x i39> <i39 274877906943, i39 274877906943>, <i39 -1, i39 -1> ;; C2 = 274877906943
+ %N = and <2 x i39> %M, <i39 274877906944, i39 274877906944>
+ %A = add <2 x i39> %N, %V
+ %B = and <2 x i39> %A, %C1
+ %D = and <2 x i39> %V, <i39 274877906943, i39 274877906943>
+ %R = or <2 x i39> %B, %D
+ ret <2 x i39> %R
+}
+
+; Test the case where Integer BitWidth > 64 && BitWidth <= 1024.
+; Vector version of test4_apint with the add and the or commuted
+define <2 x i399> @test8_apint(<2 x i399> %V, <2 x i399> %M) {
+; CHECK-LABEL: @test8_apint(
+; CHECK-NEXT: [[N:%.*]] = and <2 x i399> [[M:%.*]], <i399 18446742974197923840, i399 18446742974197923840>
+; CHECK-NEXT: [[A:%.*]] = add <2 x i399> [[N]], [[V:%.*]]
+; CHECK-NEXT: ret <2 x i399> [[A]]
+;
+ ;; If we have: ((V + N) & C1) | (V & C2)
+ ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
+ ;; replace with V+N.
+ %C1 = xor <2 x i399> <i399 274877906943, i399 274877906943>, <i399 -1, i399 -1> ;; C2 = 274877906943
+ %N = and <2 x i399> %M, <i399 18446742974197923840, i399 18446742974197923840>
+ %A = add <2 x i399> %N, %V
+ %B = and <2 x i399> %A, %C1
+ %D = and <2 x i399> %V, <i399 274877906943, i399 274877906943>
+ %R = or <2 x i399> %D, %B
+ ret <2 x i399> %R
+}
More information about the llvm-commits
mailing list