[llvm] r253723 - Fix another infinite loop in Reassociate caused by Constant::isZero().

Owen Anderson via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 20 14:34:48 PST 2015


Author: resistor
Date: Fri Nov 20 16:34:48 2015
New Revision: 253723

URL: http://llvm.org/viewvc/llvm-project?rev=253723&view=rev
Log:
Fix another infinite loop in Reassociate caused by Constant::isZero().

Not all zero vectors are ConstantDataVector's.

Modified:
    llvm/trunk/lib/IR/Constants.cpp
    llvm/trunk/test/Transforms/Reassociate/fp-expr.ll

Modified: llvm/trunk/lib/IR/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Constants.cpp?rev=253723&r1=253722&r2=253723&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Constants.cpp (original)
+++ llvm/trunk/lib/IR/Constants.cpp Fri Nov 20 16:34:48 2015
@@ -53,6 +53,11 @@ bool Constant::isNegativeZeroValue() con
       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;
@@ -73,6 +78,11 @@ bool Constant::isZeroValue() const {
     if (ConstantFP *SplatCFP = dyn_cast_or_null<ConstantFP>(CV->getSplatValue()))
       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();

Modified: llvm/trunk/test/Transforms/Reassociate/fp-expr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Reassociate/fp-expr.ll?rev=253723&r1=253722&r2=253723&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/Reassociate/fp-expr.ll (original)
+++ llvm/trunk/test/Transforms/Reassociate/fp-expr.ll Fri Nov 20 16:34:48 2015
@@ -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()
 




More information about the llvm-commits mailing list