[polly] 955b91c - [Polly] Never consider non-SCoP blocks as error blocks.
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 22 23:05:16 PDT 2021
Author: Michael Kruse
Date: 2021-08-23T01:04:01-05:00
New Revision: 955b91c19c00ed4c917559a5d66d14c669dde2e3
URL: https://github.com/llvm/llvm-project/commit/955b91c19c00ed4c917559a5d66d14c669dde2e3
DIFF: https://github.com/llvm/llvm-project/commit/955b91c19c00ed4c917559a5d66d14c669dde2e3.diff
LOG: [Polly] Never consider non-SCoP blocks as error blocks.
Code outside the SCoP will be executed recardless of the code versioning
runtime check introduced by CodeGeneration. Assumption made based on
that these are never executed in Polly-optimized code does not hold.
This fixes the miscompilation of MultiSource/Applications/lambda-0.1.3
Added:
polly/test/ScopInfo/condition-after-error-block-before-scop.ll
Modified:
polly/lib/Analysis/ScopBuilder.cpp
polly/lib/Analysis/ScopDetection.cpp
Removed:
################################################################################
diff --git a/polly/lib/Analysis/ScopBuilder.cpp b/polly/lib/Analysis/ScopBuilder.cpp
index cb15f59939b63..78f4f5337383a 100644
--- a/polly/lib/Analysis/ScopBuilder.cpp
+++ b/polly/lib/Analysis/ScopBuilder.cpp
@@ -449,6 +449,9 @@ bool ScopBuilder::buildConditionSets(
} else if (auto *PHI = dyn_cast<PHINode>(Condition)) {
auto *Unique = dyn_cast<ConstantInt>(
getUniqueNonErrorValue(PHI, &scop->getRegion(), &SD));
+ assert(Unique &&
+ "A PHINode condition should only be accepted by ScopDetection if "
+ "getUniqueNonErrorValue returns non-NULL");
if (Unique->isZero())
ConsequenceCondSet = isl_set_empty(isl_set_get_space(Domain));
diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp
index 1b4f3c92e0d36..51d8ddd274431 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -1417,6 +1417,11 @@ static bool isErrorBlockImpl(BasicBlock &BB, const Region &R, LoopInfo &LI,
if (LI.isLoopHeader(&BB))
return false;
+ // Don't consider something outside the SCoP as error block. It will precede
+ // the code versioning runtime check.
+ if (!R.contains(&BB))
+ return false;
+
// Basic blocks that are always executed are not considered error blocks,
// as their execution can not be a rare event.
bool DominatesAllPredecessors = true;
diff --git a/polly/test/ScopInfo/condition-after-error-block-before-scop.ll b/polly/test/ScopInfo/condition-after-error-block-before-scop.ll
new file mode 100644
index 0000000000000..1de4a64c12513
--- /dev/null
+++ b/polly/test/ScopInfo/condition-after-error-block-before-scop.ll
@@ -0,0 +1,48 @@
+; RUN: opt %loadPolly -polly-scops -polly-codegen -S < %s | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+%class.node = type { i32 (...)**, %class.node* }
+
+define void @foobar(double* %A) {
+if.end:
+ br i1 undef, label %if.then29, label %lor.lhs.false
+
+lor.lhs.false:
+ %call25 = tail call i32 undef(%class.node* undef)
+ br i1 undef, label %if.then29, label %if.end30
+
+if.then29:
+ br label %if.end30
+
+if.end30:
+ %tobool76.not = phi i1 [ false, %lor.lhs.false ], [ true, %if.then29 ]
+ br label %if.end75
+
+if.end75:
+ br label %if.end79
+
+if.end79:
+ br label %if.then84
+
+if.then84:
+ br label %if.end91
+
+if.end91:
+ br i1 %tobool76.not, label %if.end98, label %if.then93
+
+if.then93:
+ store double 0.0, double* %A
+ br label %if.end98
+
+if.end98:
+ %tobool131 = phi i1 [ false, %if.end91 ], [ true, %if.then93 ]
+ ret void
+}
+
+
+; CHECK: polly.stmt.if.then93:
+; CHECK: store double 0.000000e+00, double* %A
+; CHECK: br label %polly.exiting
+
More information about the llvm-commits
mailing list