Skip to content

Commit 297ce4d

Browse files
vmustyapszymich
authored andcommitted
Enable i64 emulation for select with pointer args in VC
If the target device does not support 64-bit integer arithmetic ops, VC should emulate select operation for the following case: %3 = select i1, i8* %1, i8* %2
1 parent 2a0be19 commit 297ce4d

File tree

1 file changed

+43
-14
lines changed

1 file changed

+43
-14
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXEmulate.cpp

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -563,26 +563,34 @@ class GenXEmulate : public ModulePass {
563563
} // end namespace
564564

565565
bool GenXEmulate::Emu64Expander::isI64PointerOp(const Instruction &I) {
566-
auto Opcode = I.getOpcode();
567566
const DataLayout &DL = I.getModule()->getDataLayout();
568-
if (Opcode == Instruction::ICmp) {
567+
568+
switch (I.getOpcode()) {
569+
default:
570+
break;
571+
case Instruction::ICmp: {
569572
auto *OpSTy = I.getOperand(0)->getType()->getScalarType();
570573
if (!OpSTy->isPointerTy())
571574
return false;
572-
if (DL.getTypeSizeInBits(OpSTy) < 64)
575+
return DL.getTypeSizeInBits(OpSTy) == 64;
576+
}
577+
case Instruction::Select: {
578+
auto *ReSTy = I.getType()->getScalarType();
579+
if (!ReSTy->isPointerTy())
573580
return false;
574-
return true;
581+
return DL.getTypeSizeInBits(ReSTy) == 64;
575582
}
576-
if (Opcode == Instruction::PtrToInt || Opcode == Instruction::IntToPtr) {
577-
auto *PtrType = I.getType()->getScalarType();
578-
auto *IntType = I.getOperand(0)->getType()->getScalarType();
579-
if (Opcode == Instruction::PtrToInt)
580-
std::swap(PtrType, IntType);
583+
case Instruction::PtrToInt:
584+
case Instruction::IntToPtr: {
585+
auto *OpSTy = I.getOperand(0)->getType()->getScalarType();
586+
auto *ReSTy = I.getType()->getScalarType();
581587
if (cast<CastInst>(&I)->isNoopCast(DL))
582588
return false;
583-
return (DL.getTypeSizeInBits(PtrType) == 64 ||
584-
DL.getTypeSizeInBits(IntType) == 64);
589+
return (DL.getTypeSizeInBits(OpSTy) == 64 ||
590+
DL.getTypeSizeInBits(ReSTy) == 64);
591+
}
585592
}
593+
586594
return false;
587595
}
588596
bool GenXEmulate::Emu64Expander::isConvertOfI64(const Instruction &I) {
@@ -830,11 +838,33 @@ bool GenXEmulate::Emu64Expander::getConstantUI32Values(
830838
return true;
831839
}
832840
Value *GenXEmulate::Emu64Expander::visitSelectInst(SelectInst &I) {
841+
auto Builder = getIRBuilder();
842+
auto *Cond = I.getCondition();
843+
844+
if (isI64PointerOp(I)) {
845+
if (!OptProcessPtrs) {
846+
LLVM_DEBUG(dbgs() << "i64-emu::WARNING: " << I << " won't be emulated\n");
847+
return nullptr;
848+
}
849+
850+
Type *I64Ty = Builder.getInt64Ty();
851+
auto *PtrTy = I.getType();
852+
853+
if (I.getType()->isVectorTy()) {
854+
auto NumElements =
855+
cast<IGCLLVM::FixedVectorType>(I.getType())->getNumElements();
856+
I64Ty = IGCLLVM::FixedVectorType::get(I64Ty, NumElements);
857+
}
858+
859+
auto *ITrue = Builder.CreatePtrToInt(I.getOperand(1), I64Ty);
860+
auto *IFalse = Builder.CreatePtrToInt(I.getOperand(2), I64Ty);
861+
auto *NewSel = Builder.CreateSelect(Cond, ITrue, IFalse);
862+
return Builder.CreateIntToPtr(ensureEmulated(NewSel), PtrTy);
863+
}
864+
833865
auto SrcTrue = SplitBuilder.splitOperandLoHi(1);
834866
auto SrcFalse = SplitBuilder.splitOperandLoHi(2);
835-
auto *Cond = I.getCondition();
836867

837-
auto Builder = getIRBuilder();
838868
// sel from 64-bit values transforms as:
839869
// split TrueVal and FalseVal on lo/hi parts
840870
// lo_part = self(cond, src0.l0, src1.lo)
@@ -853,7 +883,6 @@ Value *GenXEmulate::Emu64Expander::visitICmp(ICmpInst &Cmp) {
853883
auto Builder = getIRBuilder();
854884

855885
if (isI64PointerOp(Cmp)) {
856-
857886
if (!OptProcessPtrs) {
858887
LLVM_DEBUG(dbgs() << "i64-emu::WARNING: " << Cmp << " won't be emulated\n");
859888
return nullptr;

0 commit comments

Comments
 (0)