[PATCH] D98147: [SCEV] Improve modelling for pointer constants
Michael Kruse via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 8 09:25:27 PST 2021
Meinersbur added a comment.
This is my draft suggestion for changes required in Polly for this change. The main problem is that `isZero()` does not recognize a SCEVUnknown-wrapped ConstantNullExpr.
diff --git a/polly/lib/Analysis/ScopBuilder.cpp b/polly/lib/Analysis/ScopBuilder.cpp
index 4def17102925..d7cafb18e633 100644
--- a/polly/lib/Analysis/ScopBuilder.cpp
+++ b/polly/lib/Analysis/ScopBuilder.cpp
@@ -1760,6 +1760,10 @@ bool ScopBuilder::buildAccessMemIntrinsic(MemAccInst Inst, ScopStmt *Stmt) {
// as we know it would be undefined to execute this instruction anyway.
if (DestAccFunc->isZero())
return true;
+ if (auto *X = dyn_cast<SCEVUnknown>(DestAccFunc)) {
+ if (isa<ConstantPointerNull>(X->getValue()))
+ return true;
+ }
auto *DestPtrSCEV = dyn_cast<SCEVUnknown>(SE.getPointerBase(DestAccFunc));
assert(DestPtrSCEV);
@@ -1836,6 +1840,10 @@ bool ScopBuilder::buildAccessCallInst(MemAccInst Inst, ScopStmt *Stmt) {
auto *ArgSCEV = SE.getSCEVAtScope(Arg, L);
if (ArgSCEV->isZero())
continue;
+ if (auto *X = dyn_cast<SCEVUnknown>(ArgSCEV)) {
+ if (isa<ConstantPointerNull>(X->getValue()))
+ return true;
+ }
auto *ArgBasePtr = cast<SCEVUnknown>(SE.getPointerBase(ArgSCEV));
addArrayAccess(Stmt, Inst, AccType, ArgBasePtr->getValue(),
PWACtx SCEVAffinator::complexityBailout() {
diff --git a/polly/lib/Support/SCEVValidator.cpp b/polly/lib/Support/SCEVValidator.cpp
index 94b55167a9b4..0e0ec7358571 100644
--- a/polly/lib/Support/SCEVValidator.cpp
+++ b/polly/lib/Support/SCEVValidator.cpp
@@ -461,6 +461,11 @@ public:
}
}
+ if (Expr->getType()->isPointerTy()) {
+ if (isa<ConstantPointerNull>(V))
+ return ValidatorResult(SCEVType::INT); // "int"
+ }
+
return ValidatorResult(SCEVType::PARAM, Expr);
}
};
diff --git a/polly/test/Isl/CodeGen/partial_write_impossible_restriction.ll b/polly/test/Isl/CodeGen/partial_write_impossible_restriction.ll
index e4c2ce20b82b..3b17518a3ef4 100644
--- a/polly/test/Isl/CodeGen/partial_write_impossible_restriction.ll
+++ b/polly/test/Isl/CodeGen/partial_write_impossible_restriction.ll
@@ -7,7 +7,7 @@
;
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
-define void @partial_write_impossible_restriction() {
+define void @partial_write_impossible_restriction(i32* %.pn) {
entry:
br i1 undef, label %invoke.cont258, label %cond.true.i.i.i.i1007
@@ -15,7 +15,6 @@ cond.true.i.i.i.i1007:
br label %invoke.cont258
invoke.cont258:
- %.pn = phi i32* [ null, %cond.true.i.i.i.i1007 ], [ null, %entry ]
br label %invoke.cont274
invoke.cont274: ; preds = %invoke.cont258
@@ -49,11 +48,11 @@ if.then.i.i1141.loopexit: ; preds = %cond.end
; CHECK-LABEL: polly.stmt.cond.false:
-; CHECK: %polly.access..pn2 = getelementptr i32, i32* %.pn, i64 %polly.indvar
-; CHECK: store i32 %cond.in.sroa.speculate.load.cond.false_p_scalar_, i32* %polly.access..pn2, align 4, !alias.scope !0, !noalias !2
+; CHECK: %polly.access..pn{{[0-9]*}} = getelementptr i32, i32* %.pn, i64 %polly.indvar
+; CHECK: store i32 %cond.in.sroa.speculate.load.cond.false_p_scalar_, i32* %polly.access..pn{{[0-9]*}}, align 4, !alias.scope !0, !noalias !2
; CHECK: br label %polly.merge
-; CHECK-LABEL: polly.stmt.cond.false11:
-; CHECK: %polly.access..pn14 = getelementptr i32, i32* %.pn, i64 0
-; CHECK: store i32 %cond.in.sroa.speculate.load.cond.false_p_scalar_13, i32* %polly.access..pn14, align 4, !alias.scope !0, !noalias !2
-; CHECK: br label %polly.stmt.cond.end15
+; CHECK-LABEL: polly.stmt.cond.false{{[0-9]*}}:
+; CHECK: %polly.access..pn{{[0-9]*}} = getelementptr i32, i32* %.pn, i64 0
+; CHECK: store i32 %cond.in.sroa.speculate.load.cond.false_p_scalar_{{[0-9]*}}, i32* %polly.access..pn{{[0-9]*}}, align 4, !alias.scope !0, !noalias !2
+; CHECK: br label %polly.stmt.cond.end{{[0-9]*}}
diff --git a/polly/test/Isl/CodeGen/scev_looking_through_bitcasts.ll b/polly/test/Isl/CodeGen/scev_looking_through_bitcasts.ll
index 1012e23cd3a2..ea7a9b7976dc 100644
--- a/polly/test/Isl/CodeGen/scev_looking_through_bitcasts.ll
+++ b/polly/test/Isl/CodeGen/scev_looking_through_bitcasts.ll
@@ -31,7 +31,8 @@ bitmap_element_allocate.exit:
}
-; CHECK: polly.stmt.cond.end73.i:
-; CHECK-NEXT: %0 = bitcast %structty** %b.s2a to i8**
-; CHECK-NEXT: store i8* undef, i8** %0
+; CHECK: polly.stmt.cond.end73.i:
+; CHECK-NEXT: %scevgep = getelementptr i8, i8* null, i64 %a
+; CHECK-NEXT: %scevgep1 = bitcast i8* %scevgep to %structty*
+; CHECK-NEXT: store %structty* %scevgep1, %structty** %b.s2a, align 8
; CHECK-NEXT: br label %polly.exiting
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D98147/new/
https://reviews.llvm.org/D98147
More information about the llvm-commits
mailing list