Skip to content

Commit 8863ed6

Browse files
mnaczkigcbot
authored andcommitted
Emulate 64 bit @llvm.abs intrinsic
Add emulation of 64 bit @llvm.abs intrinsic
1 parent acedbe4 commit 8863ed6

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

IGC/Compiler/CISACodeGen/Emu64OpsPass.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,8 @@ bool InstExpander::visitCall(CallInst& Call) {
19121912
OutputHi = IRB->CreateExtractElement(V, IRB->getInt32(1));
19131913
};
19141914

1915+
IGC_ASSERT(nullptr != Emu);
1916+
19151917
const Function* F = Call.getCalledFunction();
19161918
if (F && F->isDeclaration()) {
19171919
switch (F->getIntrinsicID()) {
@@ -1930,9 +1932,32 @@ bool InstExpander::visitCall(CallInst& Call) {
19301932
case Intrinsic::invariant_start:
19311933
case Intrinsic::invariant_end:
19321934
return false;
1935+
#if LLVM_VERSION_MAJOR >= 12
1936+
// emulate @llvm.abs.i64
1937+
case Intrinsic::abs:
1938+
{
1939+
Value* OldVal = Call.getArgOperand(0);
1940+
Value* Lo = nullptr, * Hi = nullptr;
1941+
std::tie(Lo, Hi) = Emu->getExpandedValues(OldVal);
1942+
1943+
Value* Cmp = IRB->CreateICmpSLT(Hi, IRB->getInt32(0));
1944+
1945+
GenISAIntrinsic::ID GIID = GenISAIntrinsic::GenISA_sub_pair;
1946+
Function* IFunc = GenISAIntrinsic::getDeclaration(Emu->getModule(), GIID);
1947+
Value* Sub = IRB->CreateCall4(IFunc, IRB->getInt32(0), IRB->getInt32(0), Lo, Hi);
1948+
1949+
Value* SubLo = IRB->CreateExtractValue(Sub, 0);
1950+
Value* SubHi = IRB->CreateExtractValue(Sub, 1);
1951+
1952+
Value* SelectLo = IRB->CreateSelect(Cmp, SubLo, Lo);
1953+
Value* SelectHo = IRB->CreateSelect(Cmp, SubHi, Hi);
1954+
1955+
Emu->setExpandedValues(&Call, SelectLo, SelectHo);
1956+
return true;
1957+
}
1958+
#endif
19331959
}
19341960
}
1935-
IGC_ASSERT(nullptr != Emu);
19361961
bool doInt64BitCall = Emu->isInt64(&Call);
19371962
if (!doInt64BitCall) {
19381963
for (auto& Op : Call.operands()) {

0 commit comments

Comments
 (0)