Skip to content

Commit 6ba42ba

Browse files
ustachowigcbot
authored andcommitted
32-bit hi/lo swap of 64-bit data in vectors fails fix
Adds scalarization for fshl operation
1 parent 7aab427 commit 6ba42ba

File tree

2 files changed

+83
-5
lines changed

2 files changed

+83
-5
lines changed

IGC/Compiler/Optimizer/Scalarizer.cpp

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2017-2023 Intel Corporation
3+
Copyright (C) 2017-2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -400,9 +400,9 @@ void ScalarizeFunction::dispatchInstructionToScalarize(Instruction* I)
400400
case Instruction::ShuffleVector:
401401
scalarizeInstruction(dyn_cast<ShuffleVectorInst>(I));
402402
break;
403-
//case Instruction::Call :
404-
// scalarizeInstruction(dyn_cast<CallInst>(I));
405-
// break;
403+
case Instruction::Call :
404+
scalarizeInstruction(dyn_cast<CallInst>(I));
405+
break;
406406
case Instruction::Alloca:
407407
scalarizeInstruction(dyn_cast<AllocaInst>(I));
408408
break;
@@ -1024,7 +1024,52 @@ void ScalarizeFunction::scalarizeInstruction(CallInst* CI)
10241024
V_PRINT(scalarizer, "\t\tCall instruction\n");
10251025
IGC_ASSERT_MESSAGE(CI, "instruction type dynamic cast failed");
10261026

1027-
recoverNonScalarizableInst(CI);
1027+
Function* CalledFunc = CI->getCalledFunction();
1028+
if (CalledFunc && CalledFunc->getName().startswith("llvm.fshl"))
1029+
{
1030+
V_PRINT(scalarizer, "\t\tScalarizing fshl intrinsic\n");
1031+
1032+
IGCLLVM::FixedVectorType* instType = dyn_cast<IGCLLVM::FixedVectorType>(CI->getType());
1033+
if (!instType) {
1034+
recoverNonScalarizableInst(CI);
1035+
return;
1036+
}
1037+
1038+
SCMEntry* newEntry = getSCMEntry(CI);
1039+
1040+
unsigned numElements = int_cast<unsigned>(instType->getNumElements());
1041+
1042+
SmallVector<Value*, MAX_INPUT_VECTOR_WIDTH> operand0;
1043+
SmallVector<Value*, MAX_INPUT_VECTOR_WIDTH> operand1;
1044+
SmallVector<Value*, MAX_INPUT_VECTOR_WIDTH> operand2;
1045+
bool op0IsConst, op1IsConst, op2IsConst;
1046+
1047+
obtainScalarizedValues(operand0, &op0IsConst, CI->getOperand(0), CI);
1048+
obtainScalarizedValues(operand1, &op1IsConst, CI->getOperand(1), CI);
1049+
obtainScalarizedValues(operand2, &op2IsConst, CI->getOperand(2), CI);
1050+
1051+
SmallVector<Value*, MAX_INPUT_VECTOR_WIDTH> newScalarizedInsts;
1052+
newScalarizedInsts.resize(numElements);
1053+
for (unsigned i = 0; i < numElements; i++)
1054+
{
1055+
Type* scalarType = operand0[i]->getType();
1056+
Value* scalarFshl = CallInst::Create(
1057+
Intrinsic::getDeclaration(CI->getModule(), Intrinsic::fshl, { scalarType }),
1058+
{ operand0[i], operand1[i], operand2[i] },
1059+
CI->getName() + ".scalar",
1060+
CI
1061+
);
1062+
newScalarizedInsts[i] = scalarFshl;
1063+
}
1064+
1065+
updateSCMEntryWithValues(newEntry, &(newScalarizedInsts[0]), CI, true);
1066+
1067+
m_removedInsts.insert(CI);
1068+
}
1069+
else
1070+
{
1071+
recoverNonScalarizableInst(CI);
1072+
}
10281073
}
10291074

10301075
void ScalarizeFunction::scalarizeInstruction(AllocaInst* AI)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2024 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
;
9+
; RUN: igc_opt --igc-scalarize -S < %s | FileCheck %s
10+
; ------------------------------------------------
11+
; ScalarizeFunction
12+
; ------------------------------------------------
13+
14+
declare <4 x i64> @llvm.fshl.v4i64(<4 x i64>, <4 x i64>, <4 x i64>)
15+
declare <2 x i32> @llvm.fshl.v2i32(<2 x i32>, <2 x i32>, <2 x i32>)
16+
17+
define spir_kernel void @test_basic_v4i64(<4 x i64> %a, <4 x i64> %b, <4 x i64> %c) {
18+
; CHECK-LABEL: @test_basic_v4i64(
19+
; CHECK: call i64 @llvm.fshl.i64(i64 %{{.*}}, i64 %{{.*}}, i64 %{{.*}})
20+
; CHECK: call i64 @llvm.fshl.i64(i64 %{{.*}}, i64 %{{.*}}, i64 %{{.*}})
21+
; CHECK: call i64 @llvm.fshl.i64(i64 %{{.*}}, i64 %{{.*}}, i64 %{{.*}})
22+
; CHECK: call i64 @llvm.fshl.i64(i64 %{{.*}}, i64 %{{.*}}, i64 %{{.*}})
23+
%res = call <4 x i64> @llvm.fshl.v4i64(<4 x i64> %a, <4 x i64> %b, <4 x i64> %c)
24+
ret void
25+
}
26+
27+
define spir_kernel void @test_basic_v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c) {
28+
; CHECK-LABEL: @test_basic_v2i32(
29+
; CHECK: call i32 @llvm.fshl.i32(i32 %{{.*}}, i32 %{{.*}}, i32 %{{.*}})
30+
; CHECK: call i32 @llvm.fshl.i32(i32 %{{.*}}, i32 %{{.*}}, i32 %{{.*}})
31+
%res = call <2 x i32> @llvm.fshl.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
32+
ret void
33+
}

0 commit comments

Comments
 (0)