llvm.org GIT mirror llvm / 331a5ec
[InstCombine] don't propagate wider shufflevector arguments to predecessors InstCombine would propagate shufflevector insts that had wider output vectors onto predecessors, which would sometimes push undef's onto the divisor of a div/rem and result in bad codegen. I've fixed this by just banning propagating shufflevector back if the result of the shufflevector is wider than the input vectors. Patch by: @sheredom (Neil Henning) Differential Revision: https://reviews.llvm.org/D52548 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343329 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 1 year, 21 days ago
3 changed file(s) with 28 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
24562456
24572457 /// Return true if this shuffle returns a vector with a different number of
24582458 /// elements than its source vectors.
2459 /// Example: shufflevector <4 x n> A, <4 x n> B, <1,2>
2459 /// Examples: shufflevector <4 x n> A, <4 x n> B, <1,2,3>
2460 /// shufflevector <4 x n> A, <4 x n> B, <1,2,3,4,5>
24602461 bool changesLength() const {
24612462 unsigned NumSourceElts = Op<0>()->getType()->getVectorNumElements();
24622463 unsigned NumMaskElts = getMask()->getType()->getVectorNumElements();
24632464 return NumSourceElts != NumMaskElts;
2465 }
2466
2467 /// Return true if this shuffle returns a vector with a greater number of
2468 /// elements than its source vectors.
2469 /// Example: shufflevector <2 x n> A, <2 x n> B, <1,2,3>
2470 bool increasesLength() const {
2471 unsigned NumSourceElts = Op<0>()->getType()->getVectorNumElements();
2472 unsigned NumMaskElts = getMask()->getType()->getVectorNumElements();
2473 return NumSourceElts < NumMaskElts;
24642474 }
24652475
24662476 /// Return true if this shuffle mask chooses elements from exactly one source
14631463 if (isRHSID) return replaceInstUsesWith(SVI, RHS);
14641464 }
14651465
1466 if (isa(RHS) && CanEvaluateShuffled(LHS, Mask)) {
1466 if (isa(RHS) && !SVI.increasesLength() &&
1467 CanEvaluateShuffled(LHS, Mask)) {
14671468 Value *V = EvaluateInDifferentElementOrder(LHS, Mask);
14681469 return replaceInstUsesWith(SVI, V);
14691470 }
183183 ret <2 x i8> %D
184184 }
185185
186 ; TODO: Increasing length of vector ops is not a good canonicalization.
187
186 ; Increasing length of vector ops is not a good canonicalization.
187
188188 define <3 x i32> @add_wider(i32 %y, i32 %z) {
189 ; CHECK-LABEL: @add(
190 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <3 x i32> undef, i32 [[Y:%.*]], i32 0
191 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <3 x i32> [[TMP1]], i32 [[Z:%.*]], i32 1
192 ; CHECK-NEXT: [[TMP3:%.*]] = add <3 x i32> [[TMP2]],
193 ; CHECK-NEXT: ret <3 x i32> [[TMP3]]
189 ; CHECK-LABEL: @add_wider(
190 ; CHECK-NEXT: [[I0:%.*]] = insertelement <2 x i32> undef, i32 [[Y:%.*]], i32 0
191 ; CHECK-NEXT: [[I1:%.*]] = insertelement <2 x i32> [[I0]], i32 [[Z:%.*]], i32 1
192 ; CHECK-NEXT: [[A:%.*]] = add <2 x i32> [[I1]],
193 ; CHECK-NEXT: [[EXT:%.*]] = shufflevector <2 x i32> [[A]], <2 x i32> undef, <3 x i32>
194 ; CHECK-NEXT: ret <3 x i32> [[EXT]]
194195 ;
195196 %i0 = insertelement <2 x i32> undef, i32 %y, i32 0
196197 %i1 = insertelement <2 x i32> %i0, i32 %z, i32 1
199200 ret <3 x i32> %ext
200201 }
201202
202 ; FIXME: Increasing length of vector ops must be safe from illegal undef propagation.
203 ; Increasing length of vector ops must be safe from illegal undef propagation.
203204
204205 define <3 x i32> @div_wider(i32 %y, i32 %z) {
205 ; CHECK-LABEL: @div(
206 ; CHECK-NEXT: ret <3 x i32> undef
206 ; CHECK-LABEL: @div_wider(
207 ; CHECK-NEXT: [[I0:%.*]] = insertelement <2 x i32> undef, i32 [[Y:%.*]], i32 0
208 ; CHECK-NEXT: [[I1:%.*]] = insertelement <2 x i32> [[I0]], i32 [[Z:%.*]], i32 1
209 ; CHECK-NEXT: [[A:%.*]] = sdiv <2 x i32> [[I1]],
210 ; CHECK-NEXT: [[EXT:%.*]] = shufflevector <2 x i32> [[A]], <2 x i32> undef, <3 x i32>
211 ; CHECK-NEXT: ret <3 x i32> [[EXT]]
207212 ;
208213 %i0 = insertelement <2 x i32> undef, i32 %y, i32 0
209214 %i1 = insertelement <2 x i32> %i0, i32 %z, i32 1