From 108258ac78a89752379b431b54395298ac2ce84a Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Fri, 20 Nov 2015 22:34:48 +0000 Subject: [PATCH] Fix another infinite loop in Reassociate caused by Constant::isZero(). Not all zero vectors are ConstantDataVector's. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253723 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Constants.cpp | 10 ++++++++++ test/Transforms/Reassociate/fp-expr.ll | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/IR/Constants.cpp b/lib/IR/Constants.cpp index b237c913dcf..d79fb3e7b0b 100644 --- a/lib/IR/Constants.cpp +++ b/lib/IR/Constants.cpp @@ -53,6 +53,11 @@ bool Constant::isNegativeZeroValue() const { if (SplatCFP && SplatCFP->isZero() && SplatCFP->isNegative()) return true; + if (const ConstantVector *CV = dyn_cast(this)) + if (ConstantFP *SplatCFP = dyn_cast_or_null(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; @@ -74,6 +79,11 @@ bool Constant::isZeroValue() const { if (SplatCFP && SplatCFP->isZero()) return true; + if (const ConstantVector *CV = dyn_cast(this)) + if (ConstantFP *SplatCFP = dyn_cast_or_null(CV->getSplatValue())) + if (SplatCFP && SplatCFP->isZero()) + return true; + // Otherwise, just use +0.0. return isNullValue(); } diff --git a/test/Transforms/Reassociate/fp-expr.ll b/test/Transforms/Reassociate/fp-expr.ll index ee927069812..5af3b1991c9 100644 --- a/test/Transforms/Reassociate/fp-expr.ll +++ b/test/Transforms/Reassociate/fp-expr.ll @@ -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() -- 2.34.1