Skip to content

Commit f9d7974

Browse files
author
Colin Davidson
committed
Fix of usage of lifetime instrinsic on llvm 22
LLVM 22 drops the size parameter and forces lifetime instrinsics to directly refer to allocas rather through other objects. For this reason we make the instrinsic usage uniform.
1 parent 9c77bdf commit f9d7974

4 files changed

Lines changed: 88 additions & 20 deletions

File tree

modules/compiler/vecz/source/analysis/uniform_value_analysis.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <llvm/IR/Instructions.h>
2525
#include <llvm/IR/Module.h>
2626
#include <llvm/Support/Debug.h>
27+
#include <multi_llvm/lifetime_helper.h>
2728

2829
#include <cstdlib>
2930

@@ -358,6 +359,20 @@ void UniformValueResult::markVaryingValues(Value *V, Value *From) {
358359
return;
359360
}
360361
}
362+
#if LLVM_VERSION_GREATER_EQUAL(22, 0)
363+
// LLVM 22 drops the size parameter and requires the object
364+
// to be an alloca or a pointer to an alloca, so we force uniformity.
365+
// can drop the LifeTimeHasSizeArg() check once intel/llvm has
366+
// the size parameter removed from the intrinsic
367+
else if (auto *intrinsic = dyn_cast<llvm::IntrinsicInst>(CI)) {
368+
const auto intrinsicID = intrinsic->getIntrinsicID();
369+
if (!multi_llvm::LifeTimeHasSizeArg() &&
370+
(intrinsicID == llvm::Intrinsic::lifetime_end ||
371+
intrinsicID == llvm::Intrinsic::lifetime_start)) {
372+
return;
373+
}
374+
}
375+
#endif
361376
}
362377
}
363378

modules/compiler/vecz/source/transform/packetizer.cpp

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <llvm/Support/Debug.h>
3939
#include <llvm/Support/raw_ostream.h>
4040
#include <llvm/Transforms/Utils/LoopUtils.h>
41+
#include <multi_llvm/lifetime_helper.h>
4142
#include <multi_llvm/llvm_version.h>
4243
#include <multi_llvm/multi_llvm.h>
4344
#include <multi_llvm/vector_type_helper.h>
@@ -2050,25 +2051,33 @@ ValuePacket Packetizer::Impl::packetizeCall(CallInst *CI) {
20502051
auto IntrID = Intrinsic::ID(Callee->getIntrinsicID());
20512052
if (IntrID == llvm::Intrinsic::lifetime_end ||
20522053
IntrID == llvm::Intrinsic::lifetime_start) {
2053-
auto *ptr = CI->getOperand(1);
2054-
if (auto *const bcast = dyn_cast<BitCastInst>(ptr)) {
2055-
ptr = bcast->getOperand(0);
2056-
}
2057-
2058-
if (auto *const alloca = dyn_cast<AllocaInst>(ptr)) {
2059-
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));
2069-
results.push_back(CI);
2054+
#if LLVM_VERSION_LESS(22, 0) || 1
2055+
// LLVM 22 drops the size parameter
2056+
// Remove LifetimeHasSizeArg once intel llvm no longer has the extra
2057+
// argument
2058+
if (multi_llvm::LifeTimeHasSizeArg()) {
2059+
auto *ptr = CI->getOperand(1);
2060+
if (auto *const bcast = dyn_cast<BitCastInst>(ptr)) {
2061+
ptr = bcast->getOperand(0);
2062+
}
2063+
2064+
if (auto *const alloca = dyn_cast<AllocaInst>(ptr)) {
2065+
if (!needsInstantiation(Ctx, *alloca)) {
2066+
// If it's an alloca we can widen, we can just change the size
2067+
const llvm::TypeSize allocSize =
2068+
Ctx.dataLayout()->getTypeAllocSize(alloca->getAllocatedType());
2069+
const auto lifeSize =
2070+
allocSize.isScalable() || SimdWidth.isScalable()
2071+
? -1
2072+
: allocSize.getKnownMinValue() *
2073+
SimdWidth.getKnownMinValue();
2074+
CI->setOperand(
2075+
0, ConstantInt::get(CI->getOperand(0)->getType(), lifeSize));
2076+
results.push_back(CI);
2077+
}
20702078
}
20712079
}
2080+
#endif
20722081
return results;
20732082
}
20742083

modules/compiler/vecz/test/lit/llvm/divergent_loop_bug.ll

Lines changed: 3 additions & 3 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
@@ -60,7 +60,7 @@ entry.if.end17_crit_edge: ; preds = %entry
6060
if.then: ; preds = %entry
6161
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %cosa) #6
6262
store float 0.000000e+00, ptr %cosa, align 4
63-
%call4 = call spir_func float @_Z6sincosfPf(float 0.000000e+00, ptr nonnull %cosa) #7
63+
%call4 = call spir_func float @_Z6sincosfPf(float 0.000000e+00, ptr nonnull %cosa)
6464
%1 = load float, ptr %cosa, align 4
6565
%mul7 = fmul float %1, -2.950000e+01
6666
%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
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; Copyright (C) Codeplay Software Limited
2+
;
3+
; Licensed under the Apache License, Version 2.0 (the "License") with LLVM
4+
; Exceptions; you may not use this file except in compliance with the License.
5+
; You may obtain a copy of the License at
6+
;
7+
; https://github.com/codeplaysoftware/oneapi-construction-kit/blob/main/LICENSE.txt
8+
;
9+
; Unless required by applicable law or agreed to in writing, software
10+
; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
; License for the specific language governing permissions and limitations
13+
; under the License.
14+
;
15+
; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
16+
17+
; RUN: %pp-llvm-ver -o %t < %s --llvm-ver %LLVMVER
18+
; RUN: veczc -vecz-passes=packetizer -S < %s | FileCheck %t
19+
; REQUIRES: llvm-22+
20+
21+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
22+
target triple = "spir64-unknown-unknown"
23+
24+
declare i64 @__mux_get_global_id(i32)
25+
26+
define spir_kernel void @__vecz_v64_fract_double3() {
27+
entry:
28+
%iout.i = alloca <3 x double>, align 32
29+
%call.i = tail call i64 @__mux_get_global_id(i32 0)
30+
%cmp.i = icmp ult i64 %call.i, 0
31+
call void @llvm.lifetime.start.p0(ptr nonnull %iout.i)
32+
%.splatinsert = insertelement <4 x i1> zeroinitializer, i1 %cmp.i, i64 0
33+
call void null(<4 x double> zeroinitializer, ptr %iout.i, <4 x i1> %.splatinsert)
34+
call void @llvm.lifetime.end.p0(ptr nonnull %iout.i)
35+
ret void
36+
}
37+
; CHECK: spir_kernel void @__vecz_v4___vecz_v64_fract_double3
38+
; CHECK: %iout.i1 = alloca <3 x double>, i64 4, align 3
39+
; CHECK-GE22: call void @llvm.lifetime.start.p0(ptr nonnull %iout.i1)
40+
; CHECK-GE22: call void @llvm.lifetime.end.p0(ptr nonnull %iout.i1)
41+
; CHECK-LT22: call void @llvm.lifetime.start.p0(ptr nonnull %iout.i1)
42+
; CHECK-LT22: call void @llvm.lifetime.end.p0(ptr nonnull %iout.i1)
43+
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
44+

0 commit comments

Comments
 (0)