Skip to content

Commit

Permalink
Fix a pair of issues that caused an infinite loop in reassociate.
Browse files Browse the repository at this point in the history
Terrifyingly, one of them is a mishandling of floating point vectors
in Constant::isZero().  How exactly this issue survived this long
is beyond me.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253655 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
resistor committed Nov 20, 2015
1 parent 6be7f00 commit 3f9c290
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/IR/Constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ bool Constant::isZeroValue() const {
if (const ConstantFP *CFP = dyn_cast<ConstantFP>(this))
return CFP->isZero();

// Equivalent for a vector of -0.0's.
if (const ConstantDataVector *CV = dyn_cast<ConstantDataVector>(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
2 changes: 1 addition & 1 deletion lib/Transforms/Scalar/Reassociate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ void Reassociate::OptimizeInst(Instruction *I) {
return;

// Don't optimize floating point instructions that don't have unsafe algebra.
if (I->getType()->isFloatingPointTy() && !I->hasUnsafeAlgebra())
if (I->getType()->isFPOrFPVectorTy() && !I->hasUnsafeAlgebra())
return;

// Do not reassociate boolean (i1) expressions. We want to preserve the
Expand Down
20 changes: 20 additions & 0 deletions test/Transforms/Reassociate/fp-expr.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; RUN: opt -S -reassociate < %s | FileCheck %s

define void @test1() {
; CHECK-LABEL: @test1
; CHECK: call
; CHECK: fsub
; CHECK: fadd
%tmp = tail call <4 x float> @blam()
%tmp23 = fsub fast <4 x float> undef, %tmp
%tmp24 = fadd fast <4 x float> %tmp23, undef
tail call void @wombat(<4 x float> %tmp24)
ret void
}

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

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

0 comments on commit 3f9c290

Please sign in to comment.