[llvm-branch-commits] [llvm] [SeparateConstOffsetFromGEP] Preserve inbounds flag based on ValueTracking (PR #130617)

Fabian Ritter via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Mar 10 08:49:08 PDT 2025


================
@@ -24,3 +24,26 @@ entry:
   store float %3, ptr %arrayidx.dst, align 4
   ret void
 }
+
+; All offsets must be positive, so inbounds can be preserved.
----------------
ritter-x2a wrote:

No, the last GEP in tgt should use `%arrayidx.dst` instead of `%arrayidx.src`. Here is the IR that the patched LLVM produces:
```
define void @must_be_inbounds(ptr %dst, ptr %src, i32 %i) #0 {
entry:
  %i.prom = zext i32 %i to i64
  %0 = getelementptr inbounds float, ptr %src, i64 %i.prom
  %arrayidx.src2 = getelementptr inbounds i8, ptr %0, i64 4
  %1 = load float, ptr %arrayidx.src2, align 4
  %2 = getelementptr inbounds float, ptr %dst, i64 %i.prom
  %arrayidx.dst4 = getelementptr inbounds i8, ptr %2, i64 4
  store float %1, ptr %arrayidx.dst4, align 4
  ret void
}
```
That times out for me in the online alive2.

https://github.com/llvm/llvm-project/pull/130617


More information about the llvm-branch-commits mailing list