[llvm] [SeparateConstOffsetFromGEP] Don't set unsound inbounds flag (PR #130616)

Fabian Ritter via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 18 01:15:15 PDT 2025


================
@@ -0,0 +1,159 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+
+; RUN: llc -mtriple=amdgcn -mcpu=gfx90a -mattr=-enable-flat-scratch < %s | FileCheck --check-prefixes=GFX90A,GFX90A-MUBUF %s
+; RUN: llc -mtriple=amdgcn -mcpu=gfx90a -mattr=+enable-flat-scratch < %s | FileCheck --check-prefixes=GFX90A,GFX90A-FLATSCR %s
+; RUN: llc -mtriple=amdgcn -mcpu=gfx1030 -mattr=-enable-flat-scratch < %s | FileCheck --check-prefixes=GFX10,GFX10-MUBUF %s
+; RUN: llc -mtriple=amdgcn -mcpu=gfx1030 -mattr=+enable-flat-scratch < %s | FileCheck --check-prefixes=GFX10,GFX10-FLATSCR %s
+; RUN: llc -mtriple=amdgcn -mcpu=gfx942 < %s | FileCheck --check-prefixes=GFX942 %s
+; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 < %s | FileCheck --check-prefixes=GFX11 %s
+; RUN: llc -mtriple=amdgcn -mcpu=gfx1200 < %s | FileCheck --check-prefixes=GFX12 %s
+
+; This test checks memory addresses with constant offset components that should
+; not be folded into memory accesses with immediate offsets.
+; SeparateConstOffsetsFromGEP transforms the GEPs in a way that can lead to
+; out-of-bounds or negative intermediate results in the address computation,
+; which are problematic for flat and scratch instructions:
+;     gep[inbounds](p, i + 3) -> gep(gep(p, i), 3)
+
+
+; FIXME the offset here should not be folded: if %p points to the beginning of
+; scratch or LDS and %i is -1, a folded offset crashes the program.
+define i32 @flat_offset_maybe_oob(ptr addrspace(0) %p, i32 %i) {
----------------
ritter-x2a wrote:

Done.

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


More information about the llvm-commits mailing list