diff options
| author | Craig Topper <craig.topper@gmail.com> | 2017-04-10 16:40:00 +0000 |
|---|---|---|
| committer | Craig Topper <craig.topper@gmail.com> | 2017-04-10 16:40:00 +0000 |
| commit | 3eec73e20b8fce19bf2754b270968e876fb31e9d (patch) | |
| tree | e131bedaa0a1253e93cfac4b4db424a0d82526cd | |
| parent | 8c1cc5abbb0e2fe0df8019b2bcd10b465021fc24 (diff) | |
| download | bcm5719-llvm-3eec73e20b8fce19bf2754b270968e876fb31e9d.tar.gz bcm5719-llvm-3eec73e20b8fce19bf2754b270968e876fb31e9d.zip | |
[InstCombine] Support folding of add instructions with vector constants into select operations
We currently only fold scalar add of constants into selects. This improves this to support vectors too.
Differential Revision: https://reviews.llvm.org/D31683
llvm-svn: 299847
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 9 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/add.ll | 9 |
2 files changed, 5 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index c946c096821..65f72d0fb55 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1128,8 +1128,8 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { } } - if (isa<Constant>(RHS) && isa<PHINode>(LHS)) - if (Instruction *NV = FoldOpIntoPhi(I)) + if (isa<Constant>(RHS)) + if (Instruction *NV = foldOpWithConstantIntoOperand(I)) return NV; if (I.getType()->getScalarType()->isIntegerTy(1)) @@ -1200,11 +1200,6 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { return BinaryOperator::CreateAnd(NewAdd, C2); } } - - // Try to fold constant add into select arguments. - if (SelectInst *SI = dyn_cast<SelectInst>(LHS)) - if (Instruction *R = FoldOpIntoSelect(I, SI)) - return R; } // add (select X 0 (sub n A)) A --> select X A n diff --git a/llvm/test/Transforms/InstCombine/add.ll b/llvm/test/Transforms/InstCombine/add.ll index 84a48ece63f..648305d134c 100644 --- a/llvm/test/Transforms/InstCombine/add.ll +++ b/llvm/test/Transforms/InstCombine/add.ll @@ -272,8 +272,7 @@ define i32 @test19(i1 %C) { define <2 x i32> @test19vec(i1 %C) { ; CHECK-LABEL: @test19vec( -; CHECK-NEXT: [[A:%.*]] = select i1 [[C:%.*]], <2 x i32> <i32 1000, i32 1000>, <2 x i32> <i32 10, i32 10> -; CHECK-NEXT: [[V:%.*]] = add nuw nsw <2 x i32> [[A]], <i32 123, i32 123> +; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], <2 x i32> <i32 1123, i32 1123>, <2 x i32> <i32 133, i32 133> ; CHECK-NEXT: ret <2 x i32> [[V]] ; %A = select i1 %C, <2 x i32> <i32 1000, i32 1000>, <2 x i32> <i32 10, i32 10> @@ -604,8 +603,7 @@ define i32 @test42(i1 %C) { define <2 x i32> @test42vec(i1 %C) { ; CHECK-LABEL: @test42vec( -; CHECK-NEXT: [[A:%.*]] = select i1 [[C:%.*]], <2 x i32> <i32 1000, i32 1000>, <2 x i32> <i32 10, i32 10> -; CHECK-NEXT: [[V:%.*]] = add nuw nsw <2 x i32> [[A]], <i32 123, i32 123> +; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], <2 x i32> <i32 1123, i32 1123>, <2 x i32> <i32 133, i32 133> ; CHECK-NEXT: ret <2 x i32> [[V]] ; %A = select i1 %C, <2 x i32> <i32 1000, i32 1000>, <2 x i32> <i32 10, i32 10> @@ -615,8 +613,7 @@ define <2 x i32> @test42vec(i1 %C) { define <2 x i32> @test42vec2(i1 %C) { ; CHECK-LABEL: @test42vec2( -; CHECK-NEXT: [[A:%.*]] = select i1 [[C:%.*]], <2 x i32> <i32 1000, i32 2500>, <2 x i32> <i32 10, i32 30> -; CHECK-NEXT: [[V:%.*]] = add nuw nsw <2 x i32> [[A]], <i32 123, i32 333> +; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], <2 x i32> <i32 1123, i32 2833>, <2 x i32> <i32 133, i32 363> ; CHECK-NEXT: ret <2 x i32> [[V]] ; %A = select i1 %C, <2 x i32> <i32 1000, i32 2500>, <2 x i32> <i32 10, i32 30> |

