[llvm] r275691 - [InstCombine] allow X + signbit --> X ^ signbit for vector splats

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 16 11:29:27 PDT 2016


Author: spatel
Date: Sat Jul 16 13:29:26 2016
New Revision: 275691

URL: http://llvm.org/viewvc/llvm-project?rev=275691&view=rev
Log:
[InstCombine] allow X + signbit --> X ^ signbit for vector splats

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
    llvm/trunk/test/Transforms/InstCombine/apint-add.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp?rev=275691&r1=275690&r2=275691&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp Sat Jul 16 13:29:26 2016
@@ -1042,12 +1042,16 @@ Instruction *InstCombiner::visitAdd(Bina
   if (Value *V = SimplifyUsingDistributiveLaws(I))
     return replaceInstUsesWith(I, V);
 
-  if (ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
+  const APInt *Val;
+  if (match(RHS, m_APInt(Val))) {
     // X + (signbit) --> X ^ signbit
-    const APInt &Val = CI->getValue();
-    if (Val.isSignBit())
+    if (Val->isSignBit())
       return BinaryOperator::CreateXor(LHS, RHS);
+  }
 
+  // FIXME: Use the match above instead of dyn_cast to allow these transforms
+  // for splat vectors.
+  if (ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
     // See if SimplifyDemandedBits can simplify this.  This handles stuff like
     // (X & 254)+1 -> (X&254)|1
     if (SimplifyDemandedInstructionBits(I))
@@ -1149,6 +1153,9 @@ Instruction *InstCombiner::visitAdd(Bina
       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.
   if (ConstantInt *CRHS = dyn_cast<ConstantInt>(RHS)) {
     // (X & FF00) + xx00  -> (X+xx00) & FF00
     Value *X;

Modified: llvm/trunk/test/Transforms/InstCombine/apint-add.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/apint-add.ll?rev=275691&r1=275690&r2=275691&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/apint-add.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/apint-add.ll Sat Jul 16 13:29:26 2016
@@ -36,7 +36,7 @@ define i15 @test3(i15 %x) {
 ; X + signbit --> X ^ signbit
 define <2 x i5> @test3vec(<2 x i5> %x) {
 ; CHECK-LABEL: @test3vec(
-; CHECK-NEXT:    [[Y:%.*]] = add <2 x i5> %x, <i5 -16, i5 -16>
+; CHECK-NEXT:    [[Y:%.*]] = xor <2 x i5> %x, <i5 -16, i5 -16>
 ; CHECK-NEXT:    ret <2 x i5> [[Y]]
 ;
   %y = add <2 x i5> %x, <i5 16, i5 16>




More information about the llvm-commits mailing list