Fix a pair of issues that caused an infinite loop in reassociate.
authorOwen Anderson <resistor@mac.com>
Fri, 20 Nov 2015 08:16:13 +0000 (08:16 +0000)
committerOwen Anderson <resistor@mac.com>
Fri, 20 Nov 2015 08:16:13 +0000 (08:16 +0000)
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

lib/IR/Constants.cpp
lib/Transforms/Scalar/Reassociate.cpp
test/Transforms/Reassociate/fp-expr.ll [new file with mode: 0644]

index 550d9a89a65efbcfff3bc3133a52b56a29f24b11..b237c913dcf1e6fc763afc94e8f3d53158d300ee 100644 (file)
@@ -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();
 }
index 82c79e7d9199d45efdf841646cf45cc3b19280a3..fa2f7d995c6943c680cec346af13be8a8ab40c8e 100644 (file)
@@ -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
diff --git a/test/Transforms/Reassociate/fp-expr.ll b/test/Transforms/Reassociate/fp-expr.ll
new file mode 100644 (file)
index 0000000..ee92706
--- /dev/null
@@ -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>)
+