[PATCH] D40390: [InstCombine] Don't crash on out of bounds index in the insertelement
Igor Laevsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 1 08:44:33 PST 2017
igor-laevsky updated this revision to Diff 125157.
https://reviews.llvm.org/D40390
Files:
lib/Transforms/InstCombine/InstCombineVectorOps.cpp
test/Transforms/InstCombine/out-of-bounds-indexes.ll
test/Transforms/InstCombine/vector_insertelt_shuffle.ll
Index: test/Transforms/InstCombine/vector_insertelt_shuffle.ll
===================================================================
--- test/Transforms/InstCombine/vector_insertelt_shuffle.ll
+++ test/Transforms/InstCombine/vector_insertelt_shuffle.ll
@@ -54,10 +54,10 @@
ret <4 x float> %ins6
}
+; Out of bounds index folds to undef
define <4 x float> @bazzz(<4 x float> %x) {
; CHECK-LABEL: @bazzz(
-; CHECK-NEXT: [[INS2:%.*]] = insertelement <4 x float> %x, float 2.000000e+00, i32 2
-; CHECK-NEXT: ret <4 x float> [[INS2]]
+; CHECK-NEXT: ret <4 x float> <float undef, float undef, float 2.000000e+00, float undef>
;
%ins1 = insertelement<4 x float> %x, float 1.0, i32 5
%ins2 = insertelement<4 x float> %ins1, float 2.0, i32 2
Index: test/Transforms/InstCombine/out-of-bounds-indexes.ll
===================================================================
--- test/Transforms/InstCombine/out-of-bounds-indexes.ll
+++ test/Transforms/InstCombine/out-of-bounds-indexes.ll
@@ -19,3 +19,18 @@
declare void @llvm.assume(i1)
+define void @test2(<4 x double> %a, <4 x double> %b) {
+; CHECK-LABEL: @test2(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: store i8 127, i8* undef, align 1
+; CHECK-NEXT: ret void
+;
+entry:
+ %sub.i = fsub ninf <4 x double> %a, %b
+ %I = insertelement <4 x double> %sub.i, double 0x7FEFFFFFFFFFFFFF, i64 4294967296
+ %B = lshr i8 127, 0
+ store i8 %B, i8* undef
+ store <4 x double> %I, <4 x double>* undef
+ ret void
+}
+
Index: lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -781,6 +781,10 @@
Value *ScalarOp = IE.getOperand(1);
Value *IdxOp = IE.getOperand(2);
+ if (auto *V = SimplifyInsertElementInst(
+ VecOp, ScalarOp, IdxOp, SQ.getWithInstruction(&IE)))
+ return replaceInstUsesWith(IE, V);
+
// Inserting an undef or into an undefined place, remove this.
if (isa<UndefValue>(ScalarOp) || isa<UndefValue>(IdxOp))
replaceInstUsesWith(IE, VecOp);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40390.125157.patch
Type: text/x-patch
Size: 2133 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171201/5aa7570a/attachment.bin>
More information about the llvm-commits
mailing list