Fix another infinite loop in Reassociate caused by Constant::isZero().
authorOwen Anderson <resistor@mac.com>
Fri, 20 Nov 2015 22:34:48 +0000 (22:34 +0000)
committerOwen Anderson <resistor@mac.com>
Fri, 20 Nov 2015 22:34:48 +0000 (22:34 +0000)
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
test/Transforms/Reassociate/fp-expr.ll

index b237c913dcf1e6fc763afc94e8f3d53158d300ee..d79fb3e7b0bae084351b7fe141f656a1c3fe41da 100644 (file)
@@ -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;
@@ -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();
 }
index ee927069812432360f1cf36f9d043952bbaff774..5af3b1991c9e69ed226608b33a5ba6af48d83497 100644 (file)
@@ -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()