[llvm] r315745 - [InstCombine] move code to remove repeated constant check; NFCI
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 13 13:29:11 PDT 2017
Author: spatel
Date: Fri Oct 13 13:29:11 2017
New Revision: 315745
URL: http://llvm.org/viewvc/llvm-project?rev=315745&view=rev
Log:
[InstCombine] move code to remove repeated constant check; NFCI
Also, consolidate tests for this fold in one place.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/trunk/test/Transforms/InstCombine/add.ll
llvm/trunk/test/Transforms/InstCombine/add2.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp?rev=315745&r1=315744&r2=315745&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp Fri Oct 13 13:29:11 2017
@@ -960,10 +960,15 @@ Instruction *InstCombiner::foldAddWithCo
return NV;
Value *X;
- if (match(Op0, m_ZExt(m_Value(X))) && X->getType()->getScalarSizeInBits() == 1)
- // zext(bool) + C -> bool ? C + 1 : C
+ // zext(bool) + C -> bool ? C + 1 : C
+ if (match(Op0, m_ZExt(m_Value(X))) &&
+ X->getType()->getScalarSizeInBits() == 1)
return SelectInst::Create(X, AddOne(Op1C), Op1);
+ // ~X + C --> (C-1) - X
+ if (match(Op0, m_Not(m_Value(X))))
+ return BinaryOperator::CreateSub(SubOne(Op1C), X);
+
const APInt *C;
if (!match(Op1, m_APInt(C)))
return nullptr;
@@ -1117,12 +1122,6 @@ Instruction *InstCombiner::visitAdd(Bina
if (haveNoCommonBitsSet(LHS, RHS, DL, &AC, &I, &DT))
return BinaryOperator::CreateOr(LHS, RHS);
- if (Constant *CRHS = dyn_cast<Constant>(RHS)) {
- Value *X;
- if (match(LHS, m_Not(m_Value(X)))) // ~X + C --> (C-1) - X
- return BinaryOperator::CreateSub(SubOne(CRHS), X);
- }
-
// FIXME: We already did a check for ConstantInt RHS above this.
// FIXME: Is this pattern covered by another fold? No regression tests fail on
// removal.
Modified: llvm/trunk/test/Transforms/InstCombine/add.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/add.ll?rev=315745&r1=315744&r2=315745&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/add.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/add.ll Fri Oct 13 13:29:11 2017
@@ -266,7 +266,6 @@ define i32 @test17(i32 %A) {
; CHECK-NEXT: ret i32 [[C]]
;
%B = xor i32 %A, -1
- ; == sub int 0, %A
%C = add i32 %B, 1
ret i32 %C
}
@@ -277,11 +276,20 @@ define i8 @test18(i8 %A) {
; CHECK-NEXT: ret i8 [[C]]
;
%B = xor i8 %A, -1
- ; == sub ubyte 16, %A
%C = add i8 %B, 17
ret i8 %C
}
+define <2 x i64> @test18vec(<2 x i64> %A) {
+; CHECK-LABEL: @test18vec(
+; CHECK-NEXT: [[ADD:%.*]] = sub <2 x i64> <i64 1, i64 2>, %A
+; CHECK-NEXT: ret <2 x i64> [[ADD]]
+;
+ %xor = xor <2 x i64> %A, <i64 -1, i64 -1>
+ %add = add <2 x i64> %xor, <i64 2, i64 3>
+ ret <2 x i64> %add
+}
+
define i32 @test19(i1 %C) {
; CHECK-LABEL: @test19(
; CHECK-NEXT: [[V:%.*]] = select i1 %C, i32 1123, i32 133
Modified: llvm/trunk/test/Transforms/InstCombine/add2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/add2.ll?rev=315745&r1=315744&r2=315745&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/add2.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/add2.ll Fri Oct 13 13:29:11 2017
@@ -68,15 +68,6 @@ define <2 x i64> @test7(<2 x i64> %A) {
; CHECK-NEXT: ret <2 x i64> %add
}
-define <2 x i64> @test8(<2 x i64> %A) {
- %xor = xor <2 x i64> %A, <i64 -1, i64 -1>
- %add = add <2 x i64> %xor, <i64 2, i64 3>
- ret <2 x i64> %add
-; CHECK-LABEL: @test8(
-; CHECK-NEXT: %add = sub <2 x i64> <i64 1, i64 2>, %A
-; CHECK-NEXT: ret <2 x i64> %add
-}
-
define i16 @test9(i16 %a) {
%b = mul i16 %a, 2
%c = mul i16 %a, 32767
More information about the llvm-commits
mailing list