[PATCH] D52548: Stop instcombining propagating wider shufflevector arguments to predecessors.
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 28 08:26:50 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL343329: [InstCombine] don't propagate wider shufflevector arguments to predecessors (authored by spatel, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D52548?vs=167472&id=167481#toc
Repository:
rL LLVM
https://reviews.llvm.org/D52548
Files:
llvm/trunk/include/llvm/IR/Instructions.h
llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/trunk/test/Transforms/InstCombine/vec_shuffle.ll
Index: llvm/trunk/test/Transforms/InstCombine/vec_shuffle.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/vec_shuffle.ll
+++ llvm/trunk/test/Transforms/InstCombine/vec_shuffle.ll
@@ -184,27 +184,32 @@
ret <2 x i8> %D
}
-; TODO: Increasing length of vector ops is not a good canonicalization.
-
+; Increasing length of vector ops is not a good canonicalization.
+
define <3 x i32> @add_wider(i32 %y, i32 %z) {
-; CHECK-LABEL: @add(
-; CHECK-NEXT: [[TMP1:%.*]] = insertelement <3 x i32> undef, i32 [[Y:%.*]], i32 0
-; CHECK-NEXT: [[TMP2:%.*]] = insertelement <3 x i32> [[TMP1]], i32 [[Z:%.*]], i32 1
-; CHECK-NEXT: [[TMP3:%.*]] = add <3 x i32> [[TMP2]], <i32 255, i32 255, i32 undef>
-; CHECK-NEXT: ret <3 x i32> [[TMP3]]
+; CHECK-LABEL: @add_wider(
+; CHECK-NEXT: [[I0:%.*]] = insertelement <2 x i32> undef, i32 [[Y:%.*]], i32 0
+; CHECK-NEXT: [[I1:%.*]] = insertelement <2 x i32> [[I0]], i32 [[Z:%.*]], i32 1
+; CHECK-NEXT: [[A:%.*]] = add <2 x i32> [[I1]], <i32 255, i32 255>
+; CHECK-NEXT: [[EXT:%.*]] = shufflevector <2 x i32> [[A]], <2 x i32> undef, <3 x i32> <i32 0, i32 1, i32 undef>
+; CHECK-NEXT: ret <3 x i32> [[EXT]]
;
%i0 = insertelement <2 x i32> undef, i32 %y, i32 0
%i1 = insertelement <2 x i32> %i0, i32 %z, i32 1
%a = add <2 x i32> %i1, <i32 255, i32 255>
%ext = shufflevector <2 x i32> %a, <2 x i32> undef, <3 x i32> <i32 0, i32 1, i32 undef>
ret <3 x i32> %ext
}
-; FIXME: Increasing length of vector ops must be safe from illegal undef propagation.
+; Increasing length of vector ops must be safe from illegal undef propagation.
define <3 x i32> @div_wider(i32 %y, i32 %z) {
-; CHECK-LABEL: @div(
-; CHECK-NEXT: ret <3 x i32> undef
+; CHECK-LABEL: @div_wider(
+; CHECK-NEXT: [[I0:%.*]] = insertelement <2 x i32> undef, i32 [[Y:%.*]], i32 0
+; CHECK-NEXT: [[I1:%.*]] = insertelement <2 x i32> [[I0]], i32 [[Z:%.*]], i32 1
+; CHECK-NEXT: [[A:%.*]] = sdiv <2 x i32> [[I1]], <i32 255, i32 255>
+; CHECK-NEXT: [[EXT:%.*]] = shufflevector <2 x i32> [[A]], <2 x i32> undef, <3 x i32> <i32 0, i32 1, i32 undef>
+; CHECK-NEXT: ret <3 x i32> [[EXT]]
;
%i0 = insertelement <2 x i32> undef, i32 %y, i32 0
%i1 = insertelement <2 x i32> %i0, i32 %z, i32 1
Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -1464,7 +1464,8 @@
if (isRHSID) return replaceInstUsesWith(SVI, RHS);
}
- if (isa<UndefValue>(RHS) && CanEvaluateShuffled(LHS, Mask)) {
+ if (isa<UndefValue>(RHS) && !SVI.increasesLength() &&
+ CanEvaluateShuffled(LHS, Mask)) {
Value *V = EvaluateInDifferentElementOrder(LHS, Mask);
return replaceInstUsesWith(SVI, V);
}
Index: llvm/trunk/include/llvm/IR/Instructions.h
===================================================================
--- llvm/trunk/include/llvm/IR/Instructions.h
+++ llvm/trunk/include/llvm/IR/Instructions.h
@@ -2457,13 +2457,23 @@
/// Return true if this shuffle returns a vector with a different number of
/// elements than its source vectors.
- /// Example: shufflevector <4 x n> A, <4 x n> B, <1,2>
+ /// Examples: shufflevector <4 x n> A, <4 x n> B, <1,2,3>
+ /// shufflevector <4 x n> A, <4 x n> B, <1,2,3,4,5>
bool changesLength() const {
unsigned NumSourceElts = Op<0>()->getType()->getVectorNumElements();
unsigned NumMaskElts = getMask()->getType()->getVectorNumElements();
return NumSourceElts != NumMaskElts;
}
+ /// Return true if this shuffle returns a vector with a greater number of
+ /// elements than its source vectors.
+ /// Example: shufflevector <2 x n> A, <2 x n> B, <1,2,3>
+ bool increasesLength() const {
+ unsigned NumSourceElts = Op<0>()->getType()->getVectorNumElements();
+ unsigned NumMaskElts = getMask()->getType()->getVectorNumElements();
+ return NumSourceElts < NumMaskElts;
+ }
+
/// Return true if this shuffle mask chooses elements from exactly one source
/// vector.
/// Example: <7,5,undef,7>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52548.167481.patch
Type: text/x-patch
Size: 4237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180928/de0d080c/attachment.bin>
More information about the llvm-commits
mailing list