[clang] [cuda][[HIP] `__constant__` should imply constant (PR #110182)
Yaxun Liu via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 27 08:32:55 PDT 2024
yxsamliu wrote:
> It has nothing to do with writing to those arrays while the kernel is running. That would indeed be UB.
>
> > both would still work just the same even with this change,
>
> No, they will not. Here's the demonstration of the behavior change that `const` brings to the table: https://cuda.godbolt.org/z/h6e5Wb4PT
>
> It shows that adding `const` allows compiler to use the initializer values as written (it does not even bother instantiating `cxxx`), while without `const` it reads the array values, assuming that they may be changed externally.
EarlyCSE pass propagates the constant value https://cuda.godbolt.org/z/Ta8rKjMTo
However,
`
@xxx = dso_local addrspace(4) externally_initialized global [3 x i32] [i32 1, i32 2, i32 3], align 4
@_ZL4cxxx = internal addrspace(4) constant [3 x i32] [i32 1, i32 2, i32 3], align 4
`
In this case, _ZL4cxxx does not have externally_initialized . If this patch does not remove externally_initialized, probably this constant propagation won't happen.
Maybe Alex can add a lit test to prove that.
https://github.com/llvm/llvm-project/pull/110182
More information about the cfe-commits
mailing list