Skip to content

Commit

Permalink
PR9218: SimplifyDemandedVectorElts can return a non-null value that i…
Browse files Browse the repository at this point in the history
…s not

the instruction passed in.  Make sure to account for this correctly, instead
of looping infinitely.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126058 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
eefriedman committed Feb 19, 2011
1 parent 86b115c commit 1347623
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/Transforms/InstCombine/InstCombineVectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,11 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) {
unsigned VWidth = cast<VectorType>(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;
}
Expand All @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions test/Transforms/InstCombine/2011-02-16-InsertelementHang.ll
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 1347623

Please sign in to comment.