[llvm-branch-commits] [llvm-branch] r259245 - Merging r259236:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jan 29 13:33:02 PST 2016


Author: hans
Date: Fri Jan 29 15:33:02 2016
New Revision: 259245

URL: http://llvm.org/viewvc/llvm-project?rev=259245&view=rev
Log:
Merging r259236:
------------------------------------------------------------------------
r259236 | spatel | 2016-01-29 12:21:02 -0800 (Fri, 29 Jan 2016) | 8 lines

[InstCombine] avoid an insertelement transformation that induces the opposite extractelement fold (PR26354)

We would infinite loop because we created a shufflevector that was wider than
needed and then failed to combine that with the insertelement. When subsequently
visiting the extractelement from that shuffle, we see that it's unnecessary,
delete it, and trigger another visit to the insertelement.


------------------------------------------------------------------------

Modified:
    llvm/branches/release_38/   (props changed)
    llvm/branches/release_38/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
    llvm/branches/release_38/test/Transforms/InstCombine/insert-extract-shuffle.ll

Propchange: llvm/branches/release_38/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jan 29 15:33:02 2016
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,257645,257648,257730,257775,257791,257875,257886,257902,257905,257925,257929-257930,257940,257942,257977,257979,257997,258168,258184,258207,258221,258273,258325,258406,258416,258428,258436,258471,258690,258729,258891,258971
+/llvm/trunk:155241,257645,257648,257730,257775,257791,257875,257886,257902,257905,257925,257929-257930,257940,257942,257977,257979,257997,258168,258184,258207,258221,258273,258325,258406,258416,258428,258436,258471,258690,258729,258891,258971,259236

Modified: llvm/branches/release_38/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_38/lib/Transforms/InstCombine/InstCombineVectorOps.cpp?rev=259245&r1=259244&r2=259245&view=diff
==============================================================================
--- llvm/branches/release_38/lib/Transforms/InstCombine/InstCombineVectorOps.cpp (original)
+++ llvm/branches/release_38/lib/Transforms/InstCombine/InstCombineVectorOps.cpp Fri Jan 29 15:33:02 2016
@@ -380,6 +380,23 @@ static void replaceExtractElements(Inser
     ExtendMask.push_back(UndefValue::get(IntType));
 
   Value *ExtVecOp = ExtElt->getVectorOperand();
+  auto *ExtVecOpInst = dyn_cast<Instruction>(ExtVecOp);
+  BasicBlock *InsertionBlock = (ExtVecOpInst && !isa<PHINode>(ExtVecOpInst))
+                                   ? ExtVecOpInst->getParent()
+                                   : ExtElt->getParent();
+
+  // TODO: This restriction matches the basic block check below when creating
+  // new extractelement instructions. If that limitation is removed, this one
+  // could also be removed. But for now, we just bail out to ensure that we
+  // will replace the extractelement instruction that is feeding our
+  // insertelement instruction. This allows the insertelement to then be
+  // replaced by a shufflevector. If the insertelement is not replaced, we can
+  // induce infinite looping because there's an optimization for extractelement
+  // that will delete our widening shuffle. This would trigger another attempt
+  // here to create that shuffle, and we spin forever.
+  if (InsertionBlock != InsElt->getParent())
+    return;
+
   auto *WideVec = new ShuffleVectorInst(ExtVecOp, UndefValue::get(ExtVecType),
                                         ConstantVector::get(ExtendMask));
 
@@ -387,7 +404,6 @@ static void replaceExtractElements(Inser
   // (as long as it's not a PHI) or at the start of the basic block of the
   // extract, so any subsequent extracts in the same basic block can use it.
   // TODO: Insert before the earliest ExtractElementInst that is replaced.
-  auto *ExtVecOpInst = dyn_cast<Instruction>(ExtVecOp);
   if (ExtVecOpInst && !isa<PHINode>(ExtVecOpInst))
     WideVec->insertAfter(ExtVecOpInst);
   else

Modified: llvm/branches/release_38/test/Transforms/InstCombine/insert-extract-shuffle.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_38/test/Transforms/InstCombine/insert-extract-shuffle.ll?rev=259245&r1=259244&r2=259245&view=diff
==============================================================================
--- llvm/branches/release_38/test/Transforms/InstCombine/insert-extract-shuffle.ll (original)
+++ llvm/branches/release_38/test/Transforms/InstCombine/insert-extract-shuffle.ll Fri Jan 29 15:33:02 2016
@@ -175,3 +175,33 @@ bb3:
   ret <4 x double> %tmp4
 }
 
+; PR26354: https://llvm.org/bugs/show_bug.cgi?id=26354
+; Don't create a shufflevector if we know that we're not going to replace the insertelement.
+
+define double @pr26354(<2 x double>* %tmp, i1 %B) {
+; CHECK-LABEL: @pr26354(
+; CHECK:       %ld = load <2 x double>, <2 x double>* %tmp
+; CHECK-NEXT:  %e1 = extractelement <2 x double> %ld, i32 0
+; CHECK-NEXT:  br i1 %B, label %if, label %end
+; CHECK:       if:
+; CHECK-NEXT:  %e2 = extractelement <2 x double> %ld, i32 1
+; CHECK-NEXT:  %i1 = insertelement <4 x double>
+; CHECK-NEXT:  br label %end
+
+entry:
+  %ld = load <2 x double>, <2 x double>* %tmp
+  %e1 = extractelement <2 x double> %ld, i32 0
+  %e2 = extractelement <2 x double> %ld, i32 1
+  br i1 %B, label %if, label %end
+
+if:
+  %i1 = insertelement <4 x double> zeroinitializer, double %e2, i32 3
+  br label %end
+
+end:
+  %ph = phi <4 x double> [ undef, %entry ], [ %i1, %if ]
+  %e3 = extractelement <4 x double> %ph, i32 1
+  %mu = fmul double %e1, %e3
+  ret double %mu
+}
+




More information about the llvm-branch-commits mailing list