[llvm] [OpenMPOpt] Emit poison, not undef, for placeholder global initializers (PR #217081)

Larry Meadows via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 09:59:54 PDT 2026


https://github.com/lfmeadow created https://github.com/llvm/llvm-project/pull/217081

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


>From 55ad529ce3ed008fe70ade96bcd511fcb174f44f Mon Sep 17 00:00:00 2001
From: Larry Meadows <Lawrence.Meadows at amd.com>
Date: Tue, 18 Aug 2026 11:59:25 -0500
Subject: [PATCH] [OpenMPOpt] Emit poison, not undef, for placeholder global
 initializers

The state machine rewrite creates `<fn>.ID` as a private constant that exists
only to be compared by address; its byte is never loaded. The guarded-output
broadcast global is stored to before it is read. Both initializers are
placeholders, which is what poison is for, and undef's "any value, possibly
different per read" semantics buy nothing in either case.

The expectations that quote the `.ID` initializer are updated by hand rather
than regenerated, so the change stays one token per line. Nothing in tree
quotes the broadcast global.

Co-authored-by: Cursor <cursoragent at cursor.com>
---
 llvm/lib/Transforms/IPO/OpenMPOpt.cpp         |  4 +--
 .../OpenMP/custom_state_machines.ll           | 36 +++++++++----------
 ..._state_machine_function_ptr_replacement.ll |  4 +--
 llvm/test/Transforms/OpenMP/spmdization.ll    | 24 ++++++-------
 .../Transforms/OpenMP/spmdization_guarding.ll |  2 +-
 ...zation_no_guarding_two_reaching_kernels.ll |  2 +-
 6 files changed, 36 insertions(+), 36 deletions(-)

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



More information about the llvm-commits mailing list