Skip to content

Commit 955b91c

Browse files
committed
[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
1 parent 8e488c3 commit 955b91c

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

polly/lib/Analysis/ScopBuilder.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ bool ScopBuilder::buildConditionSets(
449449
} else if (auto *PHI = dyn_cast<PHINode>(Condition)) {
450450
auto *Unique = dyn_cast<ConstantInt>(
451451
getUniqueNonErrorValue(PHI, &scop->getRegion(), &SD));
452+
assert(Unique &&
453+
"A PHINode condition should only be accepted by ScopDetection if "
454+
"getUniqueNonErrorValue returns non-NULL");
452455

453456
if (Unique->isZero())
454457
ConsequenceCondSet = isl_set_empty(isl_set_get_space(Domain));

polly/lib/Analysis/ScopDetection.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,11 @@ static bool isErrorBlockImpl(BasicBlock &BB, const Region &R, LoopInfo &LI,
14171417
if (LI.isLoopHeader(&BB))
14181418
return false;
14191419

1420+
// Don't consider something outside the SCoP as error block. It will precede
1421+
// the code versioning runtime check.
1422+
if (!R.contains(&BB))
1423+
return false;
1424+
14201425
// Basic blocks that are always executed are not considered error blocks,
14211426
// as their execution can not be a rare event.
14221427
bool DominatesAllPredecessors = true;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; RUN: opt %loadPolly -polly-scops -polly-codegen -S < %s | FileCheck %s
2+
3+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
4+
target triple = "x86_64-unknown-linux-gnu"
5+
6+
%class.node = type { i32 (...)**, %class.node* }
7+
8+
define void @foobar(double* %A) {
9+
if.end:
10+
br i1 undef, label %if.then29, label %lor.lhs.false
11+
12+
lor.lhs.false:
13+
%call25 = tail call i32 undef(%class.node* undef)
14+
br i1 undef, label %if.then29, label %if.end30
15+
16+
if.then29:
17+
br label %if.end30
18+
19+
if.end30:
20+
%tobool76.not = phi i1 [ false, %lor.lhs.false ], [ true, %if.then29 ]
21+
br label %if.end75
22+
23+
if.end75:
24+
br label %if.end79
25+
26+
if.end79:
27+
br label %if.then84
28+
29+
if.then84:
30+
br label %if.end91
31+
32+
if.end91:
33+
br i1 %tobool76.not, label %if.end98, label %if.then93
34+
35+
if.then93:
36+
store double 0.0, double* %A
37+
br label %if.end98
38+
39+
if.end98:
40+
%tobool131 = phi i1 [ false, %if.end91 ], [ true, %if.then93 ]
41+
ret void
42+
}
43+
44+
45+
; CHECK: polly.stmt.if.then93:
46+
; CHECK: store double 0.000000e+00, double* %A
47+
; CHECK: br label %polly.exiting
48+

0 commit comments

Comments
 (0)