[llvm] r320049 - [InstCombine] Don't crash on out of bounds index in the insertelement

Igor Laevsky via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 07:00:52 PST 2017


Author: igor.laevsky
Date: Thu Dec  7 07:00:52 2017
New Revision: 320049

URL: http://llvm.org/viewvc/llvm-project?rev=320049&view=rev
Log:
[InstCombine] Don't crash on out of bounds index in the insertelement

Differential Revision: https://reviews.llvm.org/D40390


Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
    llvm/trunk/test/Transforms/InstCombine/out-of-bounds-indexes.ll
    llvm/trunk/test/Transforms/InstCombine/vector_insertelt_shuffle.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp?rev=320049&r1=320048&r2=320049&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp Thu Dec  7 07:00:52 2017
@@ -781,6 +781,10 @@ Instruction *InstCombiner::visitInsertEl
   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);

Modified: llvm/trunk/test/Transforms/InstCombine/out-of-bounds-indexes.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/out-of-bounds-indexes.ll?rev=320049&r1=320048&r2=320049&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/out-of-bounds-indexes.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/out-of-bounds-indexes.ll Thu Dec  7 07:00:52 2017
@@ -31,3 +31,11 @@ define i128 @test_non64bit(i128 %a) {
 }
 
 declare void @llvm.assume(i1)
+
+define <4 x double> @inselt_bad_index(<4 x double> %a) {
+; CHECK-LABEL: @inselt_bad_index(
+; CHECK-NEXT:    ret <4 x double> undef
+;
+  %I = insertelement <4 x double> %a, double 0.0, i64 4294967296
+  ret <4 x double> %I
+}

Modified: llvm/trunk/test/Transforms/InstCombine/vector_insertelt_shuffle.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/vector_insertelt_shuffle.ll?rev=320049&r1=320048&r2=320049&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/vector_insertelt_shuffle.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/vector_insertelt_shuffle.ll Thu Dec  7 07:00:52 2017
@@ -54,10 +54,10 @@ define <4 x float> @bazz(<4 x float> %x,
   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




More information about the llvm-commits mailing list