aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Thomas <anna@azul.com>2021-07-26 21:39:18 -0400
committerAnna Thomas <anna@azul.com>2021-07-27 09:31:44 -0400
commit68ffed12b7e29c498e5b6d563a218f8710c46e61 (patch)
tree17f2f8e3740ac24bac71e4e804196f7702b51442
parent796b84d26f4d461fb50e7b4e84e15a10eaca88fc (diff)
downloadllvm-68ffed12b7e29c498e5b6d563a218f8710c46e61.zip
llvm-68ffed12b7e29c498e5b6d563a218f8710c46e61.tar.gz
llvm-68ffed12b7e29c498e5b6d563a218f8710c46e61.tar.bz2
[IVDescriptors] Fix bug in checkOrderedReduction
The Exit instruction passed in for checking if it's an ordered reduction need not be an FPAdd operation. We need to bail out at that point instead of assuming it is an FPAdd (and hence has two operands). See added testcase. It crashes without the patch because the Exit instruction is a phi with exactly one operand. This latent bug was exposed by 95346ba which added support for multi-exit loops for vectorization. Reviewed-By: kmclaughlin Differential Revision: https://reviews.llvm.org/D106843
-rw-r--r--llvm/lib/Analysis/IVDescriptors.cpp8
-rw-r--r--llvm/test/Transforms/LoopVectorize/fp-reduction-crash.ll21
2 files changed, 24 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index 5edf9b8..fc6051b 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -199,16 +199,14 @@ static bool checkOrderedReduction(RecurKind Kind, Instruction *ExactFPMathInst,
if (Kind != RecurKind::FAdd)
return false;
- bool IsOrdered =
- Exit->getOpcode() == Instruction::FAdd && Exit == ExactFPMathInst;
+ if (Exit->getOpcode() != Instruction::FAdd || Exit != ExactFPMathInst)
+ return false;
// The only pattern accepted is the one in which the reduction PHI
// is used as one of the operands of the exit instruction
auto *LHS = Exit->getOperand(0);
auto *RHS = Exit->getOperand(1);
- IsOrdered &= ((LHS == Phi) || (RHS == Phi));
-
- if (!IsOrdered)
+ if (LHS != Phi && RHS != Phi)
return false;
LLVM_DEBUG(dbgs() << "LV: Found an ordered reduction: Phi: " << *Phi
diff --git a/llvm/test/Transforms/LoopVectorize/fp-reduction-crash.ll b/llvm/test/Transforms/LoopVectorize/fp-reduction-crash.ll
new file mode 100644
index 0000000..20d9655
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/fp-reduction-crash.ll
@@ -0,0 +1,21 @@
+; REQUIRES: asserts
+; RUN: opt < %s -loop-vectorize -S | FileCheck %s
+
+; CHECK-LABEL: quux
+define void @quux() {
+bb:
+ br label %bb4
+
+bb1: ; preds = %bb4
+ %tmp = phi double [ %tmp6, %bb4 ]
+ br i1 undef, label %bb4, label %bb2
+
+bb2: ; preds = %bb1
+ %tmp3 = phi double [ %tmp, %bb1 ]
+ ret void
+
+bb4: ; preds = %bb1, %bb
+ %tmp5 = phi double [ 1.300000e+01, %bb ], [ %tmp, %bb1 ]
+ %tmp6 = fadd double %tmp5, 1.000000e+00
+ br label %bb1
+}