llvm / llvm/llvm-project

[polly] BasePtrOriginSAI is not considered while hoisting loads

Open
#204,279 2 comments 0 reactions 1 assignee Claimed by @rahulana-quic View on GitHub
polly
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Consider the following:

```llvm
define fastcc void @foo(i32 %arg) {
bb:
br label %bb1

bb1:
%getelementptr = getelementptr i8, ptr null, i64 32
%load = load ptr, ptr %getelementptr, align 8
%load2 = load i32, ptr %load, align 4
%icmp = icmp ugt i32 %arg, 0
br i1 %icmp, label %bb3, label %bb4

bb3:
store ptr null, ptr null, align 8
br label %bb4

bb4:
ret void
}
```

From polly-debug:

```
i32 MemRef_load[*]; [BasePtrOrigin: MemRef0]
MustWriteAccess := { Stmt_bb3[] -> MemRef0[0] : arg > 0 }
```

MemRef_load has BasePtrOriginSAI = MemRef0 and MemRef0 is written inside the scop making the load of MemRef_load not invariant across the scop. But the hoisting decision in getNonHoistableCtx approves the hoist.

If the write to MemRef0 changes the stored pointer (for example, a call in the scop reallocating the object whose address is stored there) any subsequent store through the hoisted derived address is to the stale memory location, producing runtime failures.

Reproducer: https://godbolt.org/z/eTYd3jrne

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.