[clang] [cuda][HIP] `__constant__` should imply constant (PR #110182)

2024-09-27 Thread Alex Voicu via cfe-commits
https://github.com/AlexVlx updated https://github.com/llvm/llvm-project/pull/110182 >From af1adfafaa09bc7992cf9aaf34a6121cf2d56d5b Mon Sep 17 00:00:00 2001 From: Alex Voicu Date: Thu, 26 Sep 2024 04:16:52 +0100 Subject: [PATCH 1/2] Mark globals as `constant` if they have been annotated with `_

[clang] [cuda][[HIP] `__constant__` should imply constant (PR #110182)

2024-09-27 Thread Alex Voicu via cfe-commits
AlexVlx wrote: @yxsamliu beat me to it. The problem here is that the example illustrates language level const on a variable with internal linkage (which is mandatory for `__constant__` variables in non-RDC compilation AFAICT from 17.5.24.1) and we don't set externally_initialized on that, whic

[clang] [cuda][HIP] `__constant__` should imply constant (PR #110182)

2024-09-27 Thread Artem Belevich via cfe-commits
Artem-B wrote: > In this case, _ZL4cxxx does not have externally_initialized . If this patch > does not remove externally_initialized, probably this constant propagation > won't happen. Indeed, unoptimized code shows that `cxxx` has no `externally_initialized`, only `constant`. If we keep e

[clang] [cuda][HIP] `__constant__` should imply constant (PR #110182)

2024-09-27 Thread Artem Belevich via cfe-commits
https://github.com/Artem-B approved this pull request. https://github.com/llvm/llvm-project/pull/110182 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [cuda][HIP] `__constant__` should imply constant (PR #110182)

2024-09-27 Thread Alex Voicu via cfe-commits
https://github.com/AlexVlx edited https://github.com/llvm/llvm-project/pull/110182 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [cuda][[HIP] `__constant__` should imply constant (PR #110182)

2024-09-27 Thread Yaxun Liu via cfe-commits
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 tabl

[clang] [cuda][[HIP] `__constant__` should imply constant (PR #110182)

2024-09-26 Thread Matt Arsenault via cfe-commits
arsenm wrote: If it's not legal for it to be marked as constant, it's also not legal to use constant address space https://github.com/llvm/llvm-project/pull/110182 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/

[clang] [cuda][[HIP] `__constant__` should imply constant (PR #110182)

2024-09-26 Thread Artem Belevich via cfe-commits
Artem-B 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

[clang] [cuda][[HIP] `__constant__` should imply constant (PR #110182)

2024-09-26 Thread Alex Voicu via cfe-commits
AlexVlx wrote: > Well, it's certainly used that way in existing CUDA code and it's been around > forever: Here are few random examples: > > * from both 10 years ago: > > https://stackoverflow.com/questions/20535683/cuda-5-5-cudamemcpytosymbol-constant-and-out-of-scope-error > * fairly recent

[clang] [cuda][[HIP] `__constant__` should imply constant (PR #110182)

2024-09-26 Thread Artem Belevich via cfe-commits
Artem-B wrote: Well, it's certainly used that way in existing CUDA code and it's been around forever: Here are few random examples from both 10 years ago: https://stackoverflow.com/questions/20535683/cuda-5-5-cudamemcpytosymbol-constant-and-out-of-scope-error and a fairly recent example: https

[clang] [cuda][[HIP] `__constant__` should imply constant (PR #110182)

2024-09-26 Thread Artem Belevich via cfe-commits
Artem-B wrote: I'm not 100% sure that `externally_initialized` is sufficient to deal with this use pattern. IR manual says: https://llvm.org/docs/LangRef.html#global-variables > By default, global initializers are optimized by assuming that global > variables defined within the module are not

[clang] [cuda][[HIP] `__constant__` should imply constant (PR #110182)

2024-09-26 Thread Alex Voicu via cfe-commits
AlexVlx wrote: > `__constant__` may not necessarily be `const` for IR purposes. I.e. IR may > not rely on the 'known' values, as seen in IR, as the data may actually be > populated by the host via CUDA API calls `cudaMemcpyToSymbol` before the GPU > kernel launch. But since this is marked `ex

[clang] [cuda][[HIP] `__constant__` should imply constant (PR #110182)

2024-09-26 Thread Alex Voicu via cfe-commits
AlexVlx wrote: > > `__constant__` may not necessarily be `const` for IR purposes. I.e. IR may > > not rely on the 'known' values, as seen in IR, as the data may actually be > > populated by the host via CUDA API calls `cudaMemcpyToSymbol` before the > > GPU kernel launch. > > But since this i

[clang] [cuda][[HIP] `__constant__` should imply constant (PR #110182)

2024-09-26 Thread Artem Belevich via cfe-commits
Artem-B wrote: `__constant__` may not necessarily be `const` for IR purposes. I.e. IR may not rely on the 'known' values, as seen in IR, as the data may actually be populated by the host via CUDA API calls `cudaMemcpyToSymbol` before the GPU kernel launch. https://github.com/llvm/llvm-project

[clang] [cuda][[HIP] `__constant__` should imply constant (PR #110182)

2024-09-26 Thread via cfe-commits
llvmbot wrote: @llvm/pr-subscribers-clang Author: Alex Voicu (AlexVlx) Changes Currently, `__constant__` variables do not get unconditionally marked as `constant` in IR, which seems a bit odd given their definition. This is generally inconsequential for NVPTX/AMDGPU, since said variables

[clang] [cuda][[HIP] `__constant__` should imply constant (PR #110182)

2024-09-26 Thread via cfe-commits
llvmbot wrote: @llvm/pr-subscribers-clang-codegen Author: Alex Voicu (AlexVlx) Changes Currently, `__constant__` variables do not get unconditionally marked as `constant` in IR, which seems a bit odd given their definition. This is generally inconsequential for NVPTX/AMDGPU, since said v

[clang] [cuda][[HIP] `__constant__` should imply constant (PR #110182)

2024-09-26 Thread via cfe-commits
llvmbot wrote: @llvm/pr-subscribers-backend-amdgpu Author: Alex Voicu (AlexVlx) Changes Currently, `__constant__` variables do not get unconditionally marked as `constant` in IR, which seems a bit odd given their definition. This is generally inconsequential for NVPTX/AMDGPU, since said

[clang] [cuda][[HIP] `__constant__` should imply constant (PR #110182)

2024-09-26 Thread Alex Voicu via cfe-commits
https://github.com/AlexVlx created https://github.com/llvm/llvm-project/pull/110182 Currently, `__constant__` variables do not get unconditionally marked as `constant` in IR, which seems a bit odd given their definition. This is generally inconsequential for NVPTX/AMDGPU, since said variables