Skip to content

Commit c6fb72d

Browse files
committed
Revert "[InstCombine] improve demanded element analysis for vector insert-of-extract"
This reverts commit 557b890. Causing miscompiles, test case is on llvm-commits.
1 parent 6da4f11 commit c6fb72d

4 files changed

Lines changed: 31 additions & 38 deletions

File tree

‎llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,17 +1164,6 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
11641164
return I->getOperand(0);
11651165
}
11661166

1167-
// If we only demand the element that is being inserted and that element
1168-
// was extracted from the same index in another vector with the same type,
1169-
// replace this insert with that other vector.
1170-
Value *Vec;
1171-
if (PreInsertDemandedElts == 0 &&
1172-
match(I->getOperand(1),
1173-
m_ExtractElt(m_Value(Vec), m_SpecificInt(IdxNo))) &&
1174-
Vec->getType() == I->getType()) {
1175-
return Vec;
1176-
}
1177-
11781167
// The inserted element is defined.
11791168
UndefElts.clearBit(IdxNo);
11801169
break;

‎llvm/test/Transforms/InstCombine/vec_demanded_elts.ll‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,9 @@ define <4 x i8> @select_cond_(<4 x i8> %x, <4 x i8> %min, <4 x i1> %cmp, i1 %poi
749749

750750
define <4 x float> @ins_of_ext(<4 x float> %x, float %y) {
751751
; CHECK-LABEL: @ins_of_ext(
752-
; CHECK-NEXT: [[I1:%.*]] = insertelement <4 x float> [[X:%.*]], float [[Y:%.*]], i32 1
752+
; CHECK-NEXT: [[E0:%.*]] = extractelement <4 x float> [[X:%.*]], i32 0
753+
; CHECK-NEXT: [[I0:%.*]] = insertelement <4 x float> undef, float [[E0]], i32 0
754+
; CHECK-NEXT: [[I1:%.*]] = insertelement <4 x float> [[I0]], float [[Y:%.*]], i32 1
753755
; CHECK-NEXT: [[I2:%.*]] = insertelement <4 x float> [[I1]], float [[Y]], i32 2
754756
; CHECK-NEXT: [[I3:%.*]] = insertelement <4 x float> [[I2]], float [[Y]], i32 3
755757
; CHECK-NEXT: ret <4 x float> [[I3]]
@@ -764,7 +766,11 @@ define <4 x float> @ins_of_ext(<4 x float> %x, float %y) {
764766

765767
define <4 x float> @ins_of_ext_twice(<4 x float> %x, float %y) {
766768
; CHECK-LABEL: @ins_of_ext_twice(
767-
; CHECK-NEXT: [[I2:%.*]] = insertelement <4 x float> [[X:%.*]], float [[Y:%.*]], i32 2
769+
; CHECK-NEXT: [[E0:%.*]] = extractelement <4 x float> [[X:%.*]], i32 0
770+
; CHECK-NEXT: [[I0:%.*]] = insertelement <4 x float> undef, float [[E0]], i32 0
771+
; CHECK-NEXT: [[E1:%.*]] = extractelement <4 x float> [[X]], i32 1
772+
; CHECK-NEXT: [[I1:%.*]] = insertelement <4 x float> [[I0]], float [[E1]], i32 1
773+
; CHECK-NEXT: [[I2:%.*]] = insertelement <4 x float> [[I1]], float [[Y:%.*]], i32 2
768774
; CHECK-NEXT: [[I3:%.*]] = insertelement <4 x float> [[I2]], float [[Y]], i32 3
769775
; CHECK-NEXT: ret <4 x float> [[I3]]
770776
;
@@ -777,9 +783,6 @@ define <4 x float> @ins_of_ext_twice(<4 x float> %x, float %y) {
777783
ret <4 x float> %i3
778784
}
779785

780-
; Negative test - element 3 of the result must be undef to be poison safe.
781-
; TODO: Could convert insert/extract to identity shuffle with undef mask elements.
782-
783786
define <4 x float> @ins_of_ext_wrong_demand(<4 x float> %x, float %y) {
784787
; CHECK-LABEL: @ins_of_ext_wrong_demand(
785788
; CHECK-NEXT: [[E0:%.*]] = extractelement <4 x float> [[X:%.*]], i32 0
@@ -795,9 +798,6 @@ define <4 x float> @ins_of_ext_wrong_demand(<4 x float> %x, float %y) {
795798
ret <4 x float> %i2
796799
}
797800

798-
; Negative test - can't replace i0 with x.
799-
; TODO: Could convert insert/extract to identity shuffle with undef mask elements.
800-
801801
define <4 x float> @ins_of_ext_wrong_type(<5 x float> %x, float %y) {
802802
; CHECK-LABEL: @ins_of_ext_wrong_type(
803803
; CHECK-NEXT: [[E0:%.*]] = extractelement <5 x float> [[X:%.*]], i32 0

‎llvm/test/Transforms/SLPVectorizer/AArch64/getelementptr.ll‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ define i32 @getelementptr_4x32(i32* nocapture readonly %g, i32 %n, i32 %x, i32 %
5151
; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x i32> [[TMP1]], i32 [[Z:%.*]], i32 3
5252
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
5353
; CHECK: for.cond.cleanup.loopexit:
54-
; CHECK-NEXT: [[TMP3:%.*]] = extractelement <2 x i32> [[TMP20:%.*]], i32 1
54+
; CHECK-NEXT: [[TMP3:%.*]] = extractelement <2 x i32> [[TMP21:%.*]], i32 1
5555
; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
5656
; CHECK: for.cond.cleanup:
5757
; CHECK-NEXT: [[SUM_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[TMP3]], [[FOR_COND_CLEANUP_LOOPEXIT:%.*]] ]
5858
; CHECK-NEXT: ret i32 [[SUM_0_LCSSA]]
5959
; CHECK: for.body:
60-
; CHECK-NEXT: [[TMP4:%.*]] = phi <2 x i32> [ zeroinitializer, [[FOR_BODY_PREHEADER]] ], [ [[TMP20]], [[FOR_BODY]] ]
60+
; CHECK-NEXT: [[TMP4:%.*]] = phi <2 x i32> [ zeroinitializer, [[FOR_BODY_PREHEADER]] ], [ [[TMP21]], [[FOR_BODY]] ]
6161
; CHECK-NEXT: [[TMP5:%.*]] = extractelement <2 x i32> [[TMP4]], i32 0
6262
; CHECK-NEXT: [[T4:%.*]] = shl nsw i32 [[TMP5]], 1
6363
; CHECK-NEXT: [[TMP6:%.*]] = insertelement <4 x i32> undef, i32 [[T4]], i32 0
@@ -83,11 +83,12 @@ define i32 @getelementptr_4x32(i32* nocapture readonly %g, i32 %n, i32 %x, i32 %
8383
; CHECK-NEXT: [[TMP17:%.*]] = sext i32 [[TMP16]] to i64
8484
; CHECK-NEXT: [[ARRAYIDX15:%.*]] = getelementptr inbounds i32, i32* [[G]], i64 [[TMP17]]
8585
; CHECK-NEXT: [[T12:%.*]] = load i32, i32* [[ARRAYIDX15]], align 4
86-
; CHECK-NEXT: [[TMP18:%.*]] = insertelement <2 x i32> [[TMP4]], i32 [[ADD11]], i32 1
87-
; CHECK-NEXT: [[TMP19:%.*]] = insertelement <2 x i32> <i32 1, i32 undef>, i32 [[T12]], i32 1
88-
; CHECK-NEXT: [[TMP20]] = add nsw <2 x i32> [[TMP18]], [[TMP19]]
89-
; CHECK-NEXT: [[TMP21:%.*]] = extractelement <2 x i32> [[TMP20]], i32 0
90-
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[TMP21]], [[N]]
86+
; CHECK-NEXT: [[TMP18:%.*]] = insertelement <2 x i32> undef, i32 [[TMP5]], i32 0
87+
; CHECK-NEXT: [[TMP19:%.*]] = insertelement <2 x i32> [[TMP18]], i32 [[ADD11]], i32 1
88+
; CHECK-NEXT: [[TMP20:%.*]] = insertelement <2 x i32> <i32 1, i32 undef>, i32 [[T12]], i32 1
89+
; CHECK-NEXT: [[TMP21]] = add nsw <2 x i32> [[TMP19]], [[TMP20]]
90+
; CHECK-NEXT: [[TMP22:%.*]] = extractelement <2 x i32> [[TMP21]], i32 0
91+
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[TMP22]], [[N]]
9192
; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY]]
9293
;
9394
entry:
@@ -156,13 +157,13 @@ define i32 @getelementptr_2x32(i32* nocapture readonly %g, i32 %n, i32 %x, i32 %
156157
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i32> [[TMP0]], i32 [[Z:%.*]], i32 1
157158
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
158159
; CHECK: for.cond.cleanup.loopexit:
159-
; CHECK-NEXT: [[TMP2:%.*]] = extractelement <2 x i32> [[TMP17:%.*]], i32 1
160+
; CHECK-NEXT: [[TMP2:%.*]] = extractelement <2 x i32> [[TMP18:%.*]], i32 1
160161
; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
161162
; CHECK: for.cond.cleanup:
162163
; CHECK-NEXT: [[SUM_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[TMP2]], [[FOR_COND_CLEANUP_LOOPEXIT:%.*]] ]
163164
; CHECK-NEXT: ret i32 [[SUM_0_LCSSA]]
164165
; CHECK: for.body:
165-
; CHECK-NEXT: [[TMP3:%.*]] = phi <2 x i32> [ zeroinitializer, [[FOR_BODY_PREHEADER]] ], [ [[TMP17]], [[FOR_BODY]] ]
166+
; CHECK-NEXT: [[TMP3:%.*]] = phi <2 x i32> [ zeroinitializer, [[FOR_BODY_PREHEADER]] ], [ [[TMP18]], [[FOR_BODY]] ]
166167
; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x i32> [[TMP3]], i32 0
167168
; CHECK-NEXT: [[T4:%.*]] = shl nsw i32 [[TMP4]], 1
168169
; CHECK-NEXT: [[TMP5:%.*]] = sext i32 [[T4]] to i64
@@ -187,11 +188,12 @@ define i32 @getelementptr_2x32(i32* nocapture readonly %g, i32 %n, i32 %x, i32 %
187188
; CHECK-NEXT: [[TMP14:%.*]] = sext i32 [[TMP13]] to i64
188189
; CHECK-NEXT: [[ARRAYIDX15:%.*]] = getelementptr inbounds i32, i32* [[G]], i64 [[TMP14]]
189190
; CHECK-NEXT: [[T12:%.*]] = load i32, i32* [[ARRAYIDX15]], align 4
190-
; CHECK-NEXT: [[TMP15:%.*]] = insertelement <2 x i32> [[TMP3]], i32 [[ADD11]], i32 1
191-
; CHECK-NEXT: [[TMP16:%.*]] = insertelement <2 x i32> <i32 1, i32 undef>, i32 [[T12]], i32 1
192-
; CHECK-NEXT: [[TMP17]] = add nsw <2 x i32> [[TMP15]], [[TMP16]]
193-
; CHECK-NEXT: [[TMP18:%.*]] = extractelement <2 x i32> [[TMP17]], i32 0
194-
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[TMP18]], [[N]]
191+
; CHECK-NEXT: [[TMP15:%.*]] = insertelement <2 x i32> undef, i32 [[TMP4]], i32 0
192+
; CHECK-NEXT: [[TMP16:%.*]] = insertelement <2 x i32> [[TMP15]], i32 [[ADD11]], i32 1
193+
; CHECK-NEXT: [[TMP17:%.*]] = insertelement <2 x i32> <i32 1, i32 undef>, i32 [[T12]], i32 1
194+
; CHECK-NEXT: [[TMP18]] = add nsw <2 x i32> [[TMP16]], [[TMP17]]
195+
; CHECK-NEXT: [[TMP19:%.*]] = extractelement <2 x i32> [[TMP18]], i32 0
196+
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[TMP19]], [[N]]
195197
; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY]]
196198
;
197199
entry:

‎llvm/test/Transforms/SLPVectorizer/X86/operandorder.ll‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,13 @@ define void @vecload_vs_broadcast5(double * noalias %from, double * noalias %to,
183183
; CHECK-NEXT: [[P:%.*]] = phi double [ 1.000000e+00, [[LP]] ], [ 0.000000e+00, [[ENTRY:%.*]] ]
184184
; CHECK-NEXT: [[TMP0:%.*]] = bitcast double* [[FROM:%.*]] to <2 x double>*
185185
; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, <2 x double>* [[TMP0]], align 4
186-
; CHECK-NEXT: [[TMP2:%.*]] = insertelement <2 x double> [[TMP1]], double [[P]], i32 1
187-
; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <2 x double> [[TMP1]], <2 x double> undef, <2 x i32> <i32 1, i32 0>
188-
; CHECK-NEXT: [[TMP4:%.*]] = fadd <2 x double> [[TMP2]], [[TMP3]]
189-
; CHECK-NEXT: [[TMP5:%.*]] = bitcast double* [[TO:%.*]] to <2 x double>*
190-
; CHECK-NEXT: store <2 x double> [[TMP4]], <2 x double>* [[TMP5]], align 4
186+
; CHECK-NEXT: [[TMP2:%.*]] = extractelement <2 x double> [[TMP1]], i32 0
187+
; CHECK-NEXT: [[TMP3:%.*]] = insertelement <2 x double> undef, double [[TMP2]], i32 0
188+
; CHECK-NEXT: [[TMP4:%.*]] = insertelement <2 x double> [[TMP3]], double [[P]], i32 1
189+
; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <2 x double> [[TMP1]], <2 x double> undef, <2 x i32> <i32 1, i32 0>
190+
; CHECK-NEXT: [[TMP6:%.*]] = fadd <2 x double> [[TMP4]], [[TMP5]]
191+
; CHECK-NEXT: [[TMP7:%.*]] = bitcast double* [[TO:%.*]] to <2 x double>*
192+
; CHECK-NEXT: store <2 x double> [[TMP6]], <2 x double>* [[TMP7]], align 4
191193
; CHECK-NEXT: br i1 undef, label [[LP]], label [[EXT:%.*]]
192194
; CHECK: ext:
193195
; CHECK-NEXT: ret void

0 commit comments

Comments
 (0)