[PATCH] D31683: [InstCombine] Support folding of add instructions with vector constants into select operations

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 10 11:07:51 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL299847: [InstCombine] Support folding of add instructions with vector constants into… (authored by ctopper).

Changed prior to commit:
  https://reviews.llvm.org/D31683?vs=94132&id=94680#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31683

Files:
  llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
  llvm/trunk/test/Transforms/InstCombine/add.ll


Index: llvm/trunk/test/Transforms/InstCombine/add.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/add.ll
+++ llvm/trunk/test/Transforms/InstCombine/add.ll
@@ -272,8 +272,7 @@
 
 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 <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> @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>
Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
===================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1128,8 +1128,8 @@
     }
   }
 
-  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 @@
         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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31683.94680.patch
Type: text/x-patch
Size: 2644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170410/df25be2e/attachment-0001.bin>


More information about the llvm-commits mailing list