Skip to content

Commit 5a49593

Browse files
authored
Merge pull request uxlfoundation#946 from coldav/colin/fix_llvm_tip_lifetime_usage
[LLVM 22] A few more lifetime fixes
2 parents bada1fd + f90b0ae commit 5a49593

5 files changed

Lines changed: 34 additions & 21 deletions

File tree

modules/compiler/compiler_pipeline/source/remove_lifetime_intrinsics_pass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ PreservedAnalyses compiler::utils::RemoveLifetimeIntrinsicsPass::run(
4040

4141
// Second argument to intrinsic is a pointer bitcasted to `i8*`,
4242
// this can be removed since the lifetime intrinsic is the only use.
43-
auto bitcast = dyn_cast<BitCastInst>(intrinsic->getArgOperand(1));
43+
auto bitcast = dyn_cast<BitCastInst>(
44+
intrinsic->getArgOperand(intrinsic->arg_size() - 1));
4445
if (bitcast && bitcast->hasOneUse()) {
4546
toDelete.push_back(bitcast);
4647
}

modules/compiler/spirv-ll/test/spvasm/op_lifetime_sized.spvasm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
OpFunctionEnd
4444
; CHECK: ; ModuleID = '{{.*}}'
4545
; CHECK: define spir_kernel void @lifetime(ptr addrspace(3) noundef [[PTR:%.*]])
46-
; CHECK: call void @llvm.lifetime.start.p3(i64 4, ptr addrspace(3) [[PTR]])
47-
; CHECK: call void @llvm.lifetime.end.p3(i64 4, ptr addrspace(3) [[PTR]])
46+
; CHECK: call void @llvm.lifetime.start.p3({{(i64 4, )?}}ptr addrspace(3) [[PTR]])
47+
; CHECK: call void @llvm.lifetime.end.p3({{(i64 4, )?}}ptr addrspace(3) [[PTR]])
4848
; CHECK: ret void
49-
; CHECK: declare void @llvm.lifetime.start.p3(i64 immarg, ptr addrspace(3) {{nocapture|captures\(none\)}})
50-
; CHECK: declare void @llvm.lifetime.end.p3(i64 immarg, ptr addrspace(3) {{nocapture|captures\(none\)}})
49+
; CHECK: declare void @llvm.lifetime.start.p3({{(i64 immarg, )?}}ptr addrspace(3) {{nocapture|captures\(none\)}})
50+
; CHECK: declare void @llvm.lifetime.end.p3({{(i64 immarg, )?}}ptr addrspace(3) {{nocapture|captures\(none\)}})
5151
; make sure the void* type is also functioning correctly
5252
; CHECK: !{!"void*"}

modules/compiler/spirv-ll/test/spvasm/op_lifetime_unsized.spvasm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
; CHECK: [[PTR:%.*]] = alloca i32
4848
; CHECK: store i32 0, ptr [[PTR]]
4949
; LLVM 4.0 doesn't need to add the address space as it assumes 0
50-
; CHECK: call void @llvm.lifetime.start{{(.p0)?}}(i64 -1, ptr [[PTR]])
50+
; CHECK: call void @llvm.lifetime.start.p0({{(i64 -1, )?}}ptr [[PTR]])
5151
; CHECK: store i32 1, ptr [[PTR]]
52-
; CHECK: call void @llvm.lifetime.end{{(.p0)?}}(i64 -1, ptr [[PTR]])
52+
; CHECK: call void @llvm.lifetime.end.p0({{(i64 -1, )?}}ptr [[PTR]])
5353
; CHECK: store i32 424, ptr [[PTR]]
5454
; CHECK: ret void
55-
; CHECK: declare void @llvm.lifetime.start{{(.p0)?}}(i64{{.*}}, ptr {{nocapture|captures\(none\)}})
56-
; CHECK: declare void @llvm.lifetime.end{{(.p0)?}}(i64{{.*}}, ptr {{nocapture|captures\(none\)}})
55+
; CHECK: declare void @llvm.lifetime.start.p0({{(i64 immarg, )?}}ptr {{nocapture|captures\(none\)}})
56+
; CHECK: declare void @llvm.lifetime.end.p0({{(i64 immarg, )?}}ptr {{nocapture|captures\(none\)}})

modules/compiler/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
}

modules/compiler/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)