From 4c6b8bee2ab087f3b21efa6b638c6848f23b74d7 Mon Sep 17 00:00:00 2001 From: Jakub Staszak Date: Fri, 2 Sep 2011 15:43:43 +0000 Subject: [PATCH] ConstantVector returns arbitrary value for the wrong index. This fixes PR10813. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139006 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/ConstantFold.cpp | 4 ++++ test/Transforms/LoopUnroll/pr10813.ll | 29 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/Transforms/LoopUnroll/pr10813.ll diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 47c693b0306..458f224575c 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -761,6 +761,10 @@ Constant *llvm::ConstantFoldExtractElementInstruction(Constant *Val, if (ConstantVector *CVal = dyn_cast(Val)) { if (ConstantInt *CIdx = dyn_cast(Idx)) { + uint64_t Index = CIdx->getZExtValue(); + if (Index >= CVal->getNumOperands()) + // ee({w,x,y,z}, wrong_value) -> w (an arbitrary value). + return CVal->getOperand(0); return CVal->getOperand(CIdx->getZExtValue()); } else if (isa(Idx)) { // ee({w,x,y,z}, undef) -> w (an arbitrary value). diff --git a/test/Transforms/LoopUnroll/pr10813.ll b/test/Transforms/LoopUnroll/pr10813.ll new file mode 100644 index 00000000000..7daefc2f788 --- /dev/null +++ b/test/Transforms/LoopUnroll/pr10813.ll @@ -0,0 +1,29 @@ +; RUN: opt < %s -loop-unroll -disable-output + +define void @"f_fu___REFUf[]REFUf[]Uf"() nounwind { +allocas: + br i1 undef, label %cif_mask_all, label %cif_mixed_test_all + +cif_mask_all: ; preds = %allocas + unreachable + +cif_mixed_test_all: ; preds = %allocas + br label %pl_loop.i964 + +pl_loop.i964: ; preds = %pl_loopend.i973, %cif_mixed_test_all + %0 = phi i32 [ %pl_nextlane.i971, %pl_loopend.i973 ], [ 0, %cif_mixed_test_all ] + br i1 undef, label %pl_dolane.i970, label %pl_loopend.i973 + +pl_dolane.i970: ; preds = %pl_loop.i964 + %storeval.i.i969 = extractelement <4 x i8> , i32 %0 + store i8 %storeval.i.i969, i8* undef, align 1 + br label %pl_loopend.i973 + +pl_loopend.i973: ; preds = %pl_dolane.i970, %pl_loop.i964 + %pl_nextlane.i971 = add i32 %0, 1 + %exitcond5 = icmp ne i32 %pl_nextlane.i971, 5 + br i1 %exitcond5, label %pl_loop.i964, label %__scatter_base_offsets_i8.exit974 + +__scatter_base_offsets_i8.exit974: ; preds = %pl_loopend.i973 + unreachable +} -- 2.34.1