From 35ed1e5d6c7e577a9204cad965cdc5418195247d Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Sat, 19 Feb 2011 22:42:40 +0000 Subject: [PATCH] PR9218: SimplifyDemandedVectorElts can return a non-null value that is not the instruction passed in. Make sure to account for this correctly, instead of looping infinitely. llvm-svn: 126058 --- lib/Transforms/InstCombine/InstCombineVectorOps.cpp | 9 +++++++-- .../InstCombine/2011-02-16-InsertelementHang.ll | 11 +++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 test/Transforms/InstCombine/2011-02-16-InsertelementHang.ll diff --git a/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/lib/Transforms/InstCombine/InstCombineVectorOps.cpp index 4aa1328f134..5caa12dfdfa 100644 --- a/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ b/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -426,8 +426,11 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) { unsigned VWidth = cast(VecOp->getType())->getNumElements(); APInt UndefElts(VWidth, 0); APInt AllOnesEltMask(APInt::getAllOnesValue(VWidth)); - if (SimplifyDemandedVectorElts(&IE, AllOnesEltMask, UndefElts)) + if (Value *V = SimplifyDemandedVectorElts(&IE, AllOnesEltMask, UndefElts)) { + if (V != &IE) + return ReplaceInstUsesWith(IE, V); return &IE; + } return 0; } @@ -451,7 +454,9 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) { APInt UndefElts(VWidth, 0); APInt AllOnesEltMask(APInt::getAllOnesValue(VWidth)); - if (SimplifyDemandedVectorElts(&SVI, AllOnesEltMask, UndefElts)) { + if (Value *V = SimplifyDemandedVectorElts(&SVI, AllOnesEltMask, UndefElts)) { + if (V != &SVI) + return ReplaceInstUsesWith(SVI, V); LHS = SVI.getOperand(0); RHS = SVI.getOperand(1); MadeChange = true; diff --git a/test/Transforms/InstCombine/2011-02-16-InsertelementHang.ll b/test/Transforms/InstCombine/2011-02-16-InsertelementHang.ll new file mode 100644 index 00000000000..2f6034e158a --- /dev/null +++ b/test/Transforms/InstCombine/2011-02-16-InsertelementHang.ll @@ -0,0 +1,11 @@ +; RUN: opt < %s -instcombine -S | FileCheck %s +; PR9218 + +%vec2x2 = type { <2 x double>, <2 x double> } + +define %vec2x2 @split(double) nounwind alwaysinline { +; CHECK: @split +; CHECK: ret %vec2x2 undef + %vba = insertelement <2 x double> undef, double %0, i32 2 + ret <2 x double> %vba, <2 x double> %vba +}