[llvm] r253655 - Fix a pair of issues that caused an infinite loop in reassociate.

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


Author: resistor
Date: Fri Nov 20 02:16:13 2015
New Revision: 253655

URL: http://llvm.org/viewvc/llvm-project?rev=253655&view=rev
Log:
Fix a pair of issues that caused an infinite loop in reassociate.

Terrifyingly, one of them is a mishandling of floating point vectors
in Constant::isZero().  How exactly this issue survived this long
is beyond me.

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

Modified: llvm/trunk/lib/IR/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Constants.cpp?rev=253655&r1=253654&r2=253655&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Constants.cpp (original)
+++ llvm/trunk/lib/IR/Constants.cpp Fri Nov 20 02:16:13 2015
@@ -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();
 }

Modified: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp?rev=253655&r1=253654&r2=253655&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp Fri Nov 20 02:16:13 2015
@@ -2064,7 +2064,7 @@ void Reassociate::OptimizeInst(Instructi
     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

Added: llvm/trunk/test/Transforms/Reassociate/fp-expr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Reassociate/fp-expr.ll?rev=253655&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/Reassociate/fp-expr.ll (added)
+++ llvm/trunk/test/Transforms/Reassociate/fp-expr.ll Fri Nov 20 02:16:13 2015
@@ -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>)
+




More information about the llvm-commits mailing list