Skip to content

Commit 76f16d1

Browse files
hvdijkcoldav
authored andcommitted
[LLVM 22] A few more lifetime fixes.
* Obtain lifetime_(start|end) pointer argument by getting last argument. * Do not update size argument when there is no size argument. * Update tests.
1 parent 1bf2fb8 commit 76f16d1

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

llvm/lib/SYCLNativeCPUUtils/compiler_passes/vecz/source/transform/packetizer.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,22 +2050,34 @@ ValuePacket Packetizer::Impl::packetizeCall(CallInst *CI) {
20502050
auto IntrID = Intrinsic::ID(Callee->getIntrinsicID());
20512051
if (IntrID == llvm::Intrinsic::lifetime_end ||
20522052
IntrID == llvm::Intrinsic::lifetime_start) {
2053-
auto *ptr = CI->getOperand(1);
2053+
auto *ptr = CI->getArgOperand(CI->arg_size() - 1);
20542054
if (auto *const bcast = dyn_cast<BitCastInst>(ptr)) {
20552055
ptr = bcast->getOperand(0);
20562056
}
20572057

20582058
if (auto *const alloca = dyn_cast<AllocaInst>(ptr)) {
20592059
if (!needsInstantiation(Ctx, *alloca)) {
2060-
// If it's an alloca we can widen, we can just change the size
2061-
const llvm::TypeSize allocSize =
2062-
Ctx.dataLayout()->getTypeAllocSize(alloca->getAllocatedType());
2063-
const auto lifeSize =
2064-
allocSize.isScalable() || SimdWidth.isScalable()
2065-
? -1
2066-
: allocSize.getKnownMinValue() * SimdWidth.getKnownMinValue();
2067-
CI->setOperand(
2068-
0, ConstantInt::get(CI->getOperand(0)->getType(), lifeSize));
2060+
#if LLVM_VERSION_GREATER_EQUAL(23, 0)
2061+
const bool HaveSizeArg = false;
2062+
#elif LLVM_VERSION_GREATER_EQUAL(22, 0)
2063+
// TODO Remove runtime check when we no longer need to worry about
2064+
// older LLVM 22 snapshots.
2065+
const bool HaveSizeArg = CI->arg_size() == 2;
2066+
#else
2067+
const bool HaveSizeArg = true;
2068+
#endif
2069+
if (HaveSizeArg) {
2070+
// If it's an alloca we can widen, we can just change the size
2071+
const llvm::TypeSize allocSize =
2072+
Ctx.dataLayout()->getTypeAllocSize(alloca->getAllocatedType());
2073+
const auto lifeSize =
2074+
allocSize.isScalable() || SimdWidth.isScalable()
2075+
? -1
2076+
: allocSize.getKnownMinValue() *
2077+
SimdWidth.getKnownMinValue();
2078+
CI->setOperand(
2079+
0, ConstantInt::get(CI->getOperand(0)->getType(), lifeSize));
2080+
}
20692081
results.push_back(CI);
20702082
}
20712083
}

llvm/lib/SYCLNativeCPUUtils/compiler_passes/vecz/test/lit/llvm/divergent_loop_bug.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ entry.if.end17_crit_edge: ; preds = %entry
4848
; %or.cond branch.
4949
; CHECK: if.then:
5050
; CHECK: call void @__vecz_b_masked_store4_fu3ptrb(float 0.000000e+00, ptr %cosa, i1 [[CMP_NOT_NOT]])
51-
; CHECK: %1 = call spir_func float @__vecz_b_masked__Z6sincosfPf(float 0.000000e+00, ptr nonnull %cosa, i1 [[CMP_NOT_NOT]]) #9
51+
; CHECK: %1 = call spir_func float @__vecz_b_masked__Z6sincosfPf(float 0.000000e+00, ptr nonnull %cosa, i1 [[CMP_NOT_NOT]])
5252
; CHECK: %2 = call float @__vecz_b_masked_load4_fu3ptrb(ptr %cosa, i1 [[CMP_NOT_NOT]])
5353
; CHECK: %mul7 = fmul float %2, -2.950000e+01
5454
; CHECK: %cmp11 = fcmp uge float %mul7, 0.000000e+00
@@ -113,7 +113,7 @@ entry.if.end17_crit_edge: ; preds = %entry
113113
; %or.cond branch.
114114
; CHECK: if.then:
115115
; CHECK: call void @__vecz_b_masked_store4_fu3ptrb(float 0.000000e+00, ptr %cosa, i1 [[CMP_NOT_NOT]])
116-
; CHECK: %1 = call spir_func float @__vecz_b_masked__Z6sincosfPf(float 0.000000e+00, ptr nonnull %cosa, i1 [[CMP_NOT_NOT]]) #9
116+
; CHECK: %1 = call spir_func float @__vecz_b_masked__Z6sincosfPf(float 0.000000e+00, ptr nonnull %cosa, i1 [[CMP_NOT_NOT]])
117117
; CHECK: %2 = call float @__vecz_b_masked_load4_fu3ptrb(ptr %cosa, i1 [[CMP_NOT_NOT]])
118118
; CHECK: %mul7 = fmul float %2, -2.950000e+01
119119
; CHECK: %cmp11 = fcmp uge float %mul7, 0.000000e+00

0 commit comments

Comments
 (0)