[PATCH] D15981: [InstCombine] insert a new shuffle in a safe place (PR25999)
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 7 16:11:49 PST 2016
spatel created this revision.
spatel added a reviewer: ab.
spatel added a subscriber: llvm-commits.
Limit this transform to a basic block, so we don't cause chaos.
Hopefully, this fixes the remaining failures in PR25999:
https://llvm.org/bugs/show_bug.cgi?id=25999
http://reviews.llvm.org/D15981
Files:
lib/Transforms/InstCombine/InstCombineVectorOps.cpp
test/Transforms/InstCombine/insert-extract-shuffle.ll
Index: test/Transforms/InstCombine/insert-extract-shuffle.ll
===================================================================
--- test/Transforms/InstCombine/insert-extract-shuffle.ll
+++ test/Transforms/InstCombine/insert-extract-shuffle.ll
@@ -125,3 +125,29 @@
ret <8 x i16> %t6
}
+; The widening shuffle must be inserted at a valid point (after the PHIs).
+
+define <4 x double> @pr25999_phis(i1 %c, i1 %c2, <2 x double> %a, <4 x double> %b) {
+; CHECK-LABEL: @pr25999_phis(
+; CHECK: %tmp1 = phi <2 x double> [ %a, %bb1 ], [ %r, %bb2 ]
+; CHECK-NEXT: %tmp2 = phi <4 x double> [ %b, %bb1 ], [ zeroinitializer, %bb2 ]
+; CHECK-NEXT: %[[WIDEVEC:.*]] = shufflevector <2 x double> %tmp1, <2 x double> undef, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
+; CHECK-NEXT: %tmp4 = shufflevector <4 x double> %tmp2, <4 x double> %[[WIDEVEC]], <4 x i32> <i32 0, i32 1, i32 4, i32 3>
+; CHECK-NEXT: ret <4 x double> %tmp4
+bb1:
+ br i1 %c, label %bb2, label %bb3
+
+bb2:
+ %r = call <2 x double> @dummy(<2 x double> %a)
+ br label %bb3
+
+bb3:
+ %tmp1 = phi <2 x double> [ %a, %bb1 ], [ %r, %bb2 ]
+ %tmp2 = phi <4 x double> [ %b, %bb1 ], [ zeroinitializer, %bb2 ]
+ %tmp3 = extractelement <2 x double> %tmp1, i32 0
+ %tmp4 = insertelement <4 x double> %tmp2, double %tmp3, i32 2
+ ret <4 x double> %tmp4
+}
+
+declare <2 x double> @dummy(<2 x double>)
+
Index: lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -383,24 +383,16 @@
auto *WideVec = new ShuffleVectorInst(ExtVecOp, UndefValue::get(ExtVecType),
ConstantVector::get(ExtendMask));
- // Insert the new shuffle after the vector operand of the extract is defined
- // or at the start of the basic block, so any subsequent extracts can use it.
- bool ReplaceAllExtUsers;
- if (auto *ExtVecOpInst = dyn_cast<Instruction>(ExtVecOp)) {
- WideVec->insertAfter(ExtVecOpInst);
- ReplaceAllExtUsers = true;
- } else {
- // TODO: Insert at start of function, so it's always safe to replace all?
- IC.InsertNewInstWith(WideVec, *ExtElt->getParent()->getFirstInsertionPt());
- ReplaceAllExtUsers = false;
- }
+ // Insert at the start of the basic block, so any subsequent extracts in this
+ // basic block can use it.
+ // TODO: Insert at start of function, so it's safe to replace all users?
+ IC.InsertNewInstWith(WideVec, *ExtElt->getParent()->getFirstInsertionPt());
// Replace extracts from the original narrow vector with extracts from the new
// wide vector.
for (User *U : ExtVecOp->users()) {
ExtractElementInst *OldExt = dyn_cast<ExtractElementInst>(U);
- if (!OldExt ||
- (!ReplaceAllExtUsers && OldExt->getParent() != WideVec->getParent()))
+ if (!OldExt || OldExt->getParent() != WideVec->getParent())
continue;
auto *NewExt = ExtractElementInst::Create(WideVec, OldExt->getOperand(1));
NewExt->insertAfter(WideVec);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15981.44289.patch
Type: text/x-patch
Size: 3104 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160108/a7caf3c8/attachment.bin>
More information about the llvm-commits
mailing list