Skip to content

Commit

Permalink
Fix another infinite loop in Reassociate caused by Constant::isZero().
Browse files Browse the repository at this point in the history
Not all zero vectors are ConstantDataVector's.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253723 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
resistor committed Nov 20, 2015
1 parent 2d2aadf commit 108258a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/IR/Constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ bool Constant::isNegativeZeroValue() const {
if (SplatCFP && SplatCFP->isZero() && SplatCFP->isNegative())
return true;

if (const ConstantVector *CV = dyn_cast<ConstantVector>(this))
if (ConstantFP *SplatCFP = dyn_cast_or_null<ConstantFP>(CV->getSplatValue()))
if (SplatCFP && SplatCFP->isZero() && SplatCFP->isNegative())
return true;

// We've already handled true FP case; any other FP vectors can't represent -0.0.
if (getType()->isFPOrFPVectorTy())
return false;
Expand All @@ -74,6 +79,11 @@ bool Constant::isZeroValue() const {
if (SplatCFP && SplatCFP->isZero())
return true;

if (const ConstantVector *CV = dyn_cast<ConstantVector>(this))
if (ConstantFP *SplatCFP = dyn_cast_or_null<ConstantFP>(CV->getSplatValue()))
if (SplatCFP && SplatCFP->isZero())
return true;

// Otherwise, just use +0.0.
return isNullValue();
}
Expand Down
13 changes: 13 additions & 0 deletions test/Transforms/Reassociate/fp-expr.ll
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ define void @test1() {
ret void
}

define half @test2() {
; CHECK-LABEL: @test2
; CHECK: fsub
; CHECK: fsub
; CHECK: fadd
%tmp15 = fsub fast half undef, undef
%tmp17 = fsub fast half undef, %tmp15
%tmp18 = fadd fast half undef, %tmp17
ret half %tmp18
}



; Function Attrs: optsize
declare <4 x float> @blam()

Expand Down

0 comments on commit 108258a

Please sign in to comment.