[llvm] [OpenMPOpt] Emit poison, not undef, for placeholder global initializers (PR #217081)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 18 10:00:36 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Larry Meadows (lfmeadow)
<details>
<summary>Changes</summary>
Two placeholder global initializers in OpenMPOpt use `undef` where `poison` is what is meant.
`rewriteDeviceCodeStateMachine()` creates `<fn>.ID` as a private constant that exists only to be compared by address — its byte is never loaded. `AAKernelInfoFunction` creates the guarded-output broadcast global, which is stored to before it is read. In both cases `undef`'s "any value, and possibly a different one per read" semantics buy nothing over `poison`.
The expectations that quote the `.ID` initializer are edited by hand rather than regenerated, so the diff is one token per line:
```diff
-; CHECK-DAG: @<!-- -->__omp_outlined__1_wrapper.ID = private constant i8 undef
+; CHECK-DAG: @<!-- -->__omp_outlined__1_wrapper.ID = private constant i8 poison
```
Nothing in tree quotes the broadcast global.
`check-llvm` is clean: 47336 passed, 77 expectedly failed, no unexpected failures.
cc @<!-- -->jdoerfert @<!-- -->nikic
---
Full diff: https://github.com/llvm/llvm-project/pull/217081.diff
6 Files Affected:
- (modified) llvm/lib/Transforms/IPO/OpenMPOpt.cpp (+2-2)
- (modified) llvm/test/Transforms/OpenMP/custom_state_machines.ll (+18-18)
- (modified) llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll (+2-2)
- (modified) llvm/test/Transforms/OpenMP/spmdization.ll (+12-12)
- (modified) llvm/test/Transforms/OpenMP/spmdization_guarding.ll (+1-1)
- (modified) llvm/test/Transforms/OpenMP/spmdization_no_guarding_two_reaching_kernels.ll (+1-1)
``````````diff
diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 22a5efb402504..663edeb481380 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -2254,7 +2254,7 @@ bool OpenMPOpt::rewriteDeviceCodeStateMachine() {
auto *ID = new GlobalVariable(
M, Int8Ty, /* isConstant */ true, GlobalValue::PrivateLinkage,
- UndefValue::get(Int8Ty), F->getName() + ".ID");
+ PoisonValue::get(Int8Ty), F->getName() + ".ID");
for (Use *U : ToBeReplacedStateMachineUses)
U->set(ConstantExpr::getPointerBitCastOrAddrSpaceCast(
@@ -4094,7 +4094,7 @@ struct AAKernelInfoFunction : AAKernelInfo {
// value.
auto *SharedMem = new GlobalVariable(
M, I.getType(), /* IsConstant */ false,
- GlobalValue::InternalLinkage, UndefValue::get(I.getType()),
+ GlobalValue::InternalLinkage, PoisonValue::get(I.getType()),
sanitizeForGlobalName(
(I.getName() + ".guarded.output.alloc").str()),
nullptr, GlobalValue::NotThreadLocal,
diff --git a/llvm/test/Transforms/OpenMP/custom_state_machines.ll b/llvm/test/Transforms/OpenMP/custom_state_machines.ll
index a03a4b7f3fa67..c8ca7646f00c2 100644
--- a/llvm/test/Transforms/OpenMP/custom_state_machines.ll
+++ b/llvm/test/Transforms/OpenMP/custom_state_machines.ll
@@ -1010,15 +1010,15 @@ attributes #9 = { convergent nounwind willreturn memory(read) }
; AMDGPU: @__omp_offloading_14_a36502b_simple_state_machine_pure_l77_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 1, i8 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr @[[GLOB1]], ptr null }
; AMDGPU: @__omp_offloading_14_a36502b_simple_state_machine_interprocedural_nested_recursive_l92_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 1, i8 3, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr @[[GLOB1]], ptr null }
; AMDGPU: @__omp_offloading_14_a36502b_no_state_machine_weak_callee_l112_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 0, i8 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr @[[GLOB1]], ptr null }
-; AMDGPU: @__omp_outlined__2_wrapper.ID = private constant i8 undef
-; AMDGPU: @__omp_outlined__3_wrapper.ID = private constant i8 undef
-; AMDGPU: @__omp_outlined__5_wrapper.ID = private constant i8 undef
-; AMDGPU: @__omp_outlined__7_wrapper.ID = private constant i8 undef
-; AMDGPU: @__omp_outlined__8_wrapper.ID = private constant i8 undef
-; AMDGPU: @__omp_outlined__10_wrapper.ID = private constant i8 undef
-; AMDGPU: @__omp_outlined__11_wrapper.ID = private constant i8 undef
-; AMDGPU: @__omp_outlined__13_wrapper.ID = private constant i8 undef
-; AMDGPU: @__omp_outlined__14_wrapper.ID = private constant i8 undef
+; AMDGPU: @__omp_outlined__2_wrapper.ID = private constant i8 poison
+; AMDGPU: @__omp_outlined__3_wrapper.ID = private constant i8 poison
+; AMDGPU: @__omp_outlined__5_wrapper.ID = private constant i8 poison
+; AMDGPU: @__omp_outlined__7_wrapper.ID = private constant i8 poison
+; AMDGPU: @__omp_outlined__8_wrapper.ID = private constant i8 poison
+; AMDGPU: @__omp_outlined__10_wrapper.ID = private constant i8 poison
+; AMDGPU: @__omp_outlined__11_wrapper.ID = private constant i8 poison
+; AMDGPU: @__omp_outlined__13_wrapper.ID = private constant i8 poison
+; AMDGPU: @__omp_outlined__14_wrapper.ID = private constant i8 poison
;.
; NVPTX: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [23 x i8] c"
; NVPTX: @[[GLOB1:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, ptr @[[GLOB0]] }, align 8
@@ -1033,15 +1033,15 @@ attributes #9 = { convergent nounwind willreturn memory(read) }
; NVPTX: @__omp_offloading_14_a36502b_simple_state_machine_pure_l77_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 1, i8 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr @[[GLOB1]], ptr null }
; NVPTX: @__omp_offloading_14_a36502b_simple_state_machine_interprocedural_nested_recursive_l92_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 1, i8 3, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr @[[GLOB1]], ptr null }
; NVPTX: @__omp_offloading_14_a36502b_no_state_machine_weak_callee_l112_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 0, i8 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr @[[GLOB1]], ptr null }
-; NVPTX: @__omp_outlined__2_wrapper.ID = private constant i8 undef
-; NVPTX: @__omp_outlined__3_wrapper.ID = private constant i8 undef
-; NVPTX: @__omp_outlined__5_wrapper.ID = private constant i8 undef
-; NVPTX: @__omp_outlined__7_wrapper.ID = private constant i8 undef
-; NVPTX: @__omp_outlined__8_wrapper.ID = private constant i8 undef
-; NVPTX: @__omp_outlined__10_wrapper.ID = private constant i8 undef
-; NVPTX: @__omp_outlined__11_wrapper.ID = private constant i8 undef
-; NVPTX: @__omp_outlined__13_wrapper.ID = private constant i8 undef
-; NVPTX: @__omp_outlined__14_wrapper.ID = private constant i8 undef
+; NVPTX: @__omp_outlined__2_wrapper.ID = private constant i8 poison
+; NVPTX: @__omp_outlined__3_wrapper.ID = private constant i8 poison
+; NVPTX: @__omp_outlined__5_wrapper.ID = private constant i8 poison
+; NVPTX: @__omp_outlined__7_wrapper.ID = private constant i8 poison
+; NVPTX: @__omp_outlined__8_wrapper.ID = private constant i8 poison
+; NVPTX: @__omp_outlined__10_wrapper.ID = private constant i8 poison
+; NVPTX: @__omp_outlined__11_wrapper.ID = private constant i8 poison
+; NVPTX: @__omp_outlined__13_wrapper.ID = private constant i8 poison
+; NVPTX: @__omp_outlined__14_wrapper.ID = private constant i8 poison
;.
; AMDGPU-DISABLED: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [23 x i8] c"
; AMDGPU-DISABLED: @[[GLOB1:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, ptr @[[GLOB0]] }, align 8
diff --git a/llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll b/llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll
index dc915fc8c2b92..cd8bdc702a315 100644
--- a/llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll
+++ b/llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll
@@ -23,8 +23,8 @@
; region (1 and 3) but not for the middle one (2) because it could be called from
; another kernel.
-; CHECK-DAG: @__omp_outlined__1_wrapper.ID = private constant i8 undef
-; CHECK-DAG: @__omp_outlined__2_wrapper.ID = private constant i8 undef
+; CHECK-DAG: @__omp_outlined__1_wrapper.ID = private constant i8 poison
+; CHECK-DAG: @__omp_outlined__2_wrapper.ID = private constant i8 poison
; CHECK-DAG: icmp eq ptr %worker.work_fn, @__omp_outlined__1_wrapper.ID
; CHECK-DAG: icmp eq ptr %worker.work_fn, @__omp_outlined__2_wrapper.ID
diff --git a/llvm/test/Transforms/OpenMP/spmdization.ll b/llvm/test/Transforms/OpenMP/spmdization.ll
index 7d53a808ef4d3..5fef37be9ec58 100644
--- a/llvm/test/Transforms/OpenMP/spmdization.ll
+++ b/llvm/test/Transforms/OpenMP/spmdization.ll
@@ -116,7 +116,7 @@
; AMDGPU: @[[GLOB2:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @[[GLOB0]] }, align 8
; AMDGPU: @x_shared = internal addrspace(3) global [4 x i8] poison, align 4
; AMDGPU: @x_shared.1 = internal addrspace(3) global [4 x i8] poison, align 4
-; AMDGPU: @__omp_outlined__9_wrapper.ID = private constant i8 undef
+; AMDGPU: @__omp_outlined__9_wrapper.ID = private constant i8 poison
;.
; NVPTX: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [23 x i8] c"
; NVPTX: @[[GLOB1:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, ptr @[[GLOB0]] }, align 8
@@ -129,7 +129,7 @@
; NVPTX: @[[GLOB2:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @[[GLOB0]] }, align 8
; NVPTX: @x_shared = internal addrspace(3) global [4 x i8] poison, align 4
; NVPTX: @x_shared1 = internal addrspace(3) global [4 x i8] poison, align 4
-; NVPTX: @__omp_outlined__9_wrapper.ID = private constant i8 undef
+; NVPTX: @__omp_outlined__9_wrapper.ID = private constant i8 poison
;.
; AMDGPU-DISABLED1: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [23 x i8] c"
; AMDGPU-DISABLED1: @[[GLOB1:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, ptr @[[GLOB0]] }, align 8
@@ -141,11 +141,11 @@
; AMDGPU-DISABLED1: @__omp_offloading_fd02_2044372e_do_not_spmdize_task_l74_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 1, i8 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr @[[GLOB1]], ptr null }
; AMDGPU-DISABLED1: @x_shared = internal addrspace(3) global [4 x i8] poison, align 4
; AMDGPU-DISABLED1: @x_shared.1 = internal addrspace(3) global [4 x i8] poison, align 4
-; AMDGPU-DISABLED1: @__omp_outlined__1_wrapper.ID = private constant i8 undef
-; AMDGPU-DISABLED1: @__omp_outlined__3_wrapper.ID = private constant i8 undef
-; AMDGPU-DISABLED1: @__omp_outlined__5_wrapper.ID = private constant i8 undef
-; AMDGPU-DISABLED1: @__omp_outlined__7_wrapper.ID = private constant i8 undef
-; AMDGPU-DISABLED1: @__omp_outlined__9_wrapper.ID = private constant i8 undef
+; AMDGPU-DISABLED1: @__omp_outlined__1_wrapper.ID = private constant i8 poison
+; AMDGPU-DISABLED1: @__omp_outlined__3_wrapper.ID = private constant i8 poison
+; AMDGPU-DISABLED1: @__omp_outlined__5_wrapper.ID = private constant i8 poison
+; AMDGPU-DISABLED1: @__omp_outlined__7_wrapper.ID = private constant i8 poison
+; AMDGPU-DISABLED1: @__omp_outlined__9_wrapper.ID = private constant i8 poison
;.
; AMDGPU-DISABLED2: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [23 x i8] c"
; AMDGPU-DISABLED2: @[[GLOB1:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, ptr @[[GLOB0]] }, align 8
@@ -168,11 +168,11 @@
; NVPTX-DISABLED1: @__omp_offloading_fd02_2044372e_do_not_spmdize_task_l74_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 1, i8 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr @[[GLOB1]], ptr null }
; NVPTX-DISABLED1: @x_shared = internal addrspace(3) global [4 x i8] poison, align 4
; NVPTX-DISABLED1: @x_shared1 = internal addrspace(3) global [4 x i8] poison, align 4
-; NVPTX-DISABLED1: @__omp_outlined__1_wrapper.ID = private constant i8 undef
-; NVPTX-DISABLED1: @__omp_outlined__3_wrapper.ID = private constant i8 undef
-; NVPTX-DISABLED1: @__omp_outlined__5_wrapper.ID = private constant i8 undef
-; NVPTX-DISABLED1: @__omp_outlined__7_wrapper.ID = private constant i8 undef
-; NVPTX-DISABLED1: @__omp_outlined__9_wrapper.ID = private constant i8 undef
+; NVPTX-DISABLED1: @__omp_outlined__1_wrapper.ID = private constant i8 poison
+; NVPTX-DISABLED1: @__omp_outlined__3_wrapper.ID = private constant i8 poison
+; NVPTX-DISABLED1: @__omp_outlined__5_wrapper.ID = private constant i8 poison
+; NVPTX-DISABLED1: @__omp_outlined__7_wrapper.ID = private constant i8 poison
+; NVPTX-DISABLED1: @__omp_outlined__9_wrapper.ID = private constant i8 poison
;.
; NVPTX-DISABLED2: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [23 x i8] c"
; NVPTX-DISABLED2: @[[GLOB1:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, ptr @[[GLOB0]] }, align 8
diff --git a/llvm/test/Transforms/OpenMP/spmdization_guarding.ll b/llvm/test/Transforms/OpenMP/spmdization_guarding.ll
index 2fb1f878cce7b..6b10176d76aa1 100644
--- a/llvm/test/Transforms/OpenMP/spmdization_guarding.ll
+++ b/llvm/test/Transforms/OpenMP/spmdization_guarding.ll
@@ -55,7 +55,7 @@
; CHECK-DISABLED: @[[GLOB1:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, ptr @[[GLOB0]] }, align 8
; CHECK-DISABLED: @LocGlob = private unnamed_addr addrspace(5) global i32 43
; CHECK-DISABLED: @__omp_offloading_2a_fbfa7a_sequential_loop_l6_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 0, i8 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr @[[GLOB1]], ptr null }
-; CHECK-DISABLED: @__omp_outlined__1_wrapper.ID = private constant i8 undef
+; CHECK-DISABLED: @__omp_outlined__1_wrapper.ID = private constant i8 poison
;.
define weak ptx_kernel void @__omp_offloading_2a_fbfa7a_sequential_loop_l6(ptr %dyn, ptr %x, i64 %N) #0 {
; CHECK-LABEL: define {{[^@]+}}@__omp_offloading_2a_fbfa7a_sequential_loop_l6
diff --git a/llvm/test/Transforms/OpenMP/spmdization_no_guarding_two_reaching_kernels.ll b/llvm/test/Transforms/OpenMP/spmdization_no_guarding_two_reaching_kernels.ll
index 4f64839deaf53..0288bc3103e51 100644
--- a/llvm/test/Transforms/OpenMP/spmdization_no_guarding_two_reaching_kernels.ll
+++ b/llvm/test/Transforms/OpenMP/spmdization_no_guarding_two_reaching_kernels.ll
@@ -54,7 +54,7 @@
; CHECK-DISABLE-SPMDIZATION: @G = external addrspace(5) global i32, align 4
; CHECK-DISABLE-SPMDIZATION: @__omp_offloading_2b_10393b5_spmd_l12_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 0, i8 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr @[[GLOB1]], ptr null }
; CHECK-DISABLE-SPMDIZATION: @__omp_offloading_2b_10393b5_generic_l20_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 0, i8 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr @[[GLOB1]], ptr null }
-; CHECK-DISABLE-SPMDIZATION: @__omp_outlined___wrapper.ID = private constant i8 undef
+; CHECK-DISABLE-SPMDIZATION: @__omp_outlined___wrapper.ID = private constant i8 poison
;.
define weak ptx_kernel void @__omp_offloading_2b_10393b5_spmd_l12(ptr %dyn) #0 {
; CHECK-LABEL: define {{[^@]+}}@__omp_offloading_2b_10393b5_spmd_l12
``````````
</details>
https://github.com/llvm/llvm-project/pull/217081
More information about the llvm-commits
mailing list