[polly] BasePtrOriginSAI is not considered while hoisting loads
- 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
Assessment
This issue has not been assessed yet.