Skip to content

Commit 9eac90b

Browse files
vmustyaigcbot
authored andcommitted
Fix constant expression handling for 64-bit integer emulation in VC
.
1 parent cd791bd commit 9eac90b

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXUtil.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,15 +1140,23 @@ Region IVSplitter::createSplitRegion(Type *SrcTy, IVSplitter::RegionType RT) {
11401140
// function takes 64-bit constant value (vector or scalar) and splits it
11411141
// into an equivalent vector of 32-bit constant (as if it was Bitcast-ed)
11421142
static void convertI64ToI32(Constant &K, SmallVectorImpl<Constant *> &K32) {
1143-
auto I64To32 = [](const Constant &K) {
1143+
auto I64To32 = [](Constant &K) {
11441144
// we expect only scalar types here
11451145
IGC_ASSERT(!isa<VectorType>(K.getType()));
11461146
IGC_ASSERT(K.getType()->isIntegerTy(64));
1147-
auto *Ty32 = K.getType()->getInt32Ty(K.getContext());
1147+
auto *Ty32 = Type::getInt32Ty(K.getContext());
11481148
if (isa<UndefValue>(K)) {
11491149
Constant *Undef = UndefValue::get(Ty32);
11501150
return std::make_pair(Undef, Undef);
11511151
}
1152+
if (isa<ConstantExpr>(K)) {
1153+
auto *Lo = ConstantExpr::getTrunc(&K, Ty32);
1154+
auto *Amount = ConstantInt::get(K.getType(), 32);
1155+
auto *Shift = ConstantExpr::getLShr(&K, Amount);
1156+
auto *Hi = ConstantExpr::getTrunc(Shift, Ty32);
1157+
return std::make_pair(Lo, Hi);
1158+
}
1159+
IGC_ASSERT_EXIT(isa<ConstantInt>(K));
11521160
auto *KI = cast<ConstantInt>(&K);
11531161
uint64_t Val64 = KI->getZExtValue();
11541162
const auto UI32ValueMask = std::numeric_limits<uint32_t>::max();

IGC/VectorCompiler/test/Emulation/emu_i64_sel_ptr.ll

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;=========================== begin_copyright_notice ============================
22
;
3-
; Copyright (C) 2022 Intel Corporation
3+
; Copyright (C) 2022-2023 Intel Corporation
44
;
55
; SPDX-License-Identifier: MIT
66
;
@@ -70,3 +70,17 @@ define <8 x i8*> @test_vector(<8 x i1> %cond, <8 x i8*> %left, <8 x i8*> %right)
7070
%res = select <8 x i1> %cond, <8 x i8*> %left, <8 x i8*> %right
7171
ret <8 x i8*> %res
7272
}
73+
74+
; CHECK-LABEL: @test_constexpr
75+
define float addrspace(1)* @test_constexpr(i1 %cond) {
76+
; CHECK: [[SEL_LO:%[^ ]+]] = select i1 %cond, <1 x i32> zeroinitializer, <1 x i32> <i32 ptrtoint (float addrspace(1)* addrspacecast (float addrspace(4)* null to float addrspace(1)*) to i32)>
77+
; CHECK: [[SEL_HI:%[^ ]+]] = select i1 %cond, <1 x i32> zeroinitializer, <1 x i32> <i32 trunc (i64 lshr (i64 ptrtoint (float addrspace(1)* addrspacecast (float addrspace(4)* null to float addrspace(1)*) to i64), i64 32) to i32)>
78+
; CHECK: [[PART_JOIN:%[^ ]+]] = call <2 x i32> @llvm.genx.wrregioni.v2i32.v1i32.i16.i1(<2 x i32> undef, <1 x i32> [[SEL_LO]], i32 0, i32 1, i32 2, i16 0, i32 undef, i1 true)
79+
; CHECK: [[JOIN:%[^ ]+]] = call <2 x i32> @llvm.genx.wrregioni.v2i32.v1i32.i16.i1(<2 x i32> [[PART_JOIN]], <1 x i32> [[SEL_HI]], i32 0, i32 1, i32 2, i16 4, i32 undef, i1 true)
80+
; CHECK: [[VCAST:%[^ ]+]] = bitcast <2 x i32> [[JOIN]] to <1 x i64>
81+
; CHECK: [[ICAST:%[^ ]+]] = bitcast <1 x i64> [[VCAST]] to i64
82+
; CHECK: [[ITP:%[^ ]+]] = inttoptr i64 [[ICAST]] to float addrspace(1)*
83+
; CHECK: ret float addrspace(1)* [[ITP]]
84+
%res = select i1 %cond, float addrspace(1)* null, float addrspace(1)* addrspacecast(float addrspace(4)* null to float addrspace(1)*)
85+
ret float addrspace(1)* %res
86+
}

0 commit comments

Comments
 (0)