Skip to content

Commit b63292d

Browse files
[SYCL][ESIMD] Preserving undef intializer for globals in ESIMDLowerVecArg pass
1 parent af13cc6 commit b63292d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

llvm/lib/SYCLLowerIR/LowerESIMDVecArg.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,13 @@ void ESIMDLowerVecArgPass::fixGlobals(Module &M) {
272272
if (NewTy && !G.user_empty()) {
273273
// Peel off ptr type that getSimdArgPtrTyOrNull applies
274274
NewTy = NewTy->getPointerElementType();
275-
auto ZeroInit = ConstantAggregateZero::get(NewTy);
275+
auto InitVal =
276+
G.hasInitializer() && isa<UndefValue>(G.getInitializer())
277+
? static_cast<ConstantData *>(UndefValue::get(NewTy))
278+
: static_cast<ConstantData *>(ConstantAggregateZero::get(NewTy));
276279
auto NewGlobalVar =
277-
new GlobalVariable(NewTy, G.isConstant(), G.getLinkage(), ZeroInit,
278-
"", G.getThreadLocalMode(), G.getAddressSpace());
280+
new GlobalVariable(NewTy, G.isConstant(), G.getLinkage(), InitVal, "",
281+
G.getThreadLocalMode(), G.getAddressSpace());
279282
NewGlobalVar->setExternallyInitialized(G.isExternallyInitialized());
280283
NewGlobalVar->copyAttributesFrom(&G);
281284
NewGlobalVar->takeName(&G);

llvm/test/SYCLLowerIR/esimd_global_undef.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ target triple = "spir64-unknown-unknown-sycldevice"
66

77
%"class._ZTSN2cl4sycl5INTEL3gpu4simdIiLi2512EEE.cl::sycl::INTEL::gpu::simd" = type { <2512 x i32> }
88

9-
; CHECK: @GlobalGRF_data = dso_local global <2512 x i32> zeroinitializer, align 16384
9+
; CHECK: @GlobalGRF_data = dso_local global <2512 x i32> undef, align 16384
1010
@GlobalGRF_data = dso_local global %"class._ZTSN2cl4sycl5INTEL3gpu4simdIiLi2512EEE.cl::sycl::INTEL::gpu::simd" undef, align 16384
1111

1212
define void @f(<2512 x i32> %simd_val) {

0 commit comments

Comments
 (0)