@@ -563,26 +563,34 @@ class GenXEmulate : public ModulePass {
563
563
} // end namespace
564
564
565
565
bool GenXEmulate::Emu64Expander::isI64PointerOp (const Instruction &I) {
566
- auto Opcode = I.getOpcode ();
567
566
const DataLayout &DL = I.getModule ()->getDataLayout ();
568
- if (Opcode == Instruction::ICmp) {
567
+
568
+ switch (I.getOpcode ()) {
569
+ default :
570
+ break ;
571
+ case Instruction::ICmp: {
569
572
auto *OpSTy = I.getOperand (0 )->getType ()->getScalarType ();
570
573
if (!OpSTy->isPointerTy ())
571
574
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 ())
573
580
return false ;
574
- return true ;
581
+ return DL. getTypeSizeInBits (ReSTy) == 64 ;
575
582
}
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 ();
581
587
if (cast<CastInst>(&I)->isNoopCast (DL))
582
588
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
+ }
585
592
}
593
+
586
594
return false ;
587
595
}
588
596
bool GenXEmulate::Emu64Expander::isConvertOfI64 (const Instruction &I) {
@@ -830,11 +838,33 @@ bool GenXEmulate::Emu64Expander::getConstantUI32Values(
830
838
return true ;
831
839
}
832
840
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
+
833
865
auto SrcTrue = SplitBuilder.splitOperandLoHi (1 );
834
866
auto SrcFalse = SplitBuilder.splitOperandLoHi (2 );
835
- auto *Cond = I.getCondition ();
836
867
837
- auto Builder = getIRBuilder ();
838
868
// sel from 64-bit values transforms as:
839
869
// split TrueVal and FalseVal on lo/hi parts
840
870
// lo_part = self(cond, src0.l0, src1.lo)
@@ -853,7 +883,6 @@ Value *GenXEmulate::Emu64Expander::visitICmp(ICmpInst &Cmp) {
853
883
auto Builder = getIRBuilder ();
854
884
855
885
if (isI64PointerOp (Cmp)) {
856
-
857
886
if (!OptProcessPtrs) {
858
887
LLVM_DEBUG (dbgs () << " i64-emu::WARNING: " << Cmp << " won't be emulated\n " );
859
888
return nullptr ;
0 commit comments