Skip to content

Commit ea8b1bf

Browse files
[X86][FastISel] Refactor bitcast selection into separate function (NFC)
1 parent 3dfdb4d commit ea8b1bf

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

llvm/lib/Target/X86/X86FastISel.cpp

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class X86FastISel final : public FastISel {
124124
bool X86SelectSIToFP(const Instruction *I);
125125
bool X86SelectUIToFP(const Instruction *I);
126126
bool X86SelectIntToFP(const Instruction *I, bool IsSigned);
127+
bool X86SelectBitCast(const Instruction *I);
127128

128129
const X86InstrInfo *getInstrInfo() const {
129130
return Subtarget->getInstrInfo();
@@ -2546,6 +2547,36 @@ bool X86FastISel::X86SelectTrunc(const Instruction *I) {
25462547
return true;
25472548
}
25482549

2550+
bool X86FastISel::X86SelectBitCast(const Instruction *I) {
2551+
// Select SSE2/AVX bitcasts between 128/256/512 bit vector types.
2552+
MVT SrcVT, DstVT;
2553+
if (!Subtarget->hasSSE2() ||
2554+
!isTypeLegal(I->getOperand(0)->getType(), SrcVT) ||
2555+
!isTypeLegal(I->getType(), DstVT))
2556+
return false;
2557+
2558+
// Only allow vectors that use xmm/ymm/zmm.
2559+
if (!SrcVT.isVector() || !DstVT.isVector() ||
2560+
SrcVT.getVectorElementType() == MVT::i1 ||
2561+
DstVT.getVectorElementType() == MVT::i1)
2562+
return false;
2563+
2564+
Register Reg = getRegForValue(I->getOperand(0));
2565+
if (!Reg)
2566+
return false;
2567+
2568+
// Emit a reg-reg copy so we don't propagate cached known bits information
2569+
// with the wrong VT if we fall out of fast isel after selecting this.
2570+
const TargetRegisterClass *DstClass = TLI.getRegClassFor(DstVT);
2571+
Register ResultReg = createResultReg(DstClass);
2572+
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD, TII.get(TargetOpcode::COPY),
2573+
ResultReg)
2574+
.addReg(Reg);
2575+
2576+
updateValueMap(I, ResultReg);
2577+
return true;
2578+
}
2579+
25492580
bool X86FastISel::IsMemcpySmall(uint64_t Len) {
25502581
return Len <= (Subtarget->is64Bit() ? 32 : 16);
25512582
}
@@ -3693,36 +3724,8 @@ X86FastISel::fastSelectInstruction(const Instruction *I) {
36933724
updateValueMap(I, Reg);
36943725
return true;
36953726
}
3696-
case Instruction::BitCast: {
3697-
// Select SSE2/AVX bitcasts between 128/256/512 bit vector types.
3698-
if (!Subtarget->hasSSE2())
3699-
return false;
3700-
3701-
MVT SrcVT, DstVT;
3702-
if (!isTypeLegal(I->getOperand(0)->getType(), SrcVT) ||
3703-
!isTypeLegal(I->getType(), DstVT))
3704-
return false;
3705-
3706-
// Only allow vectors that use xmm/ymm/zmm.
3707-
if (!SrcVT.isVector() || !DstVT.isVector() ||
3708-
SrcVT.getVectorElementType() == MVT::i1 ||
3709-
DstVT.getVectorElementType() == MVT::i1)
3710-
return false;
3711-
3712-
Register Reg = getRegForValue(I->getOperand(0));
3713-
if (!Reg)
3714-
return false;
3715-
3716-
// Emit a reg-reg copy so we don't propagate cached known bits information
3717-
// with the wrong VT if we fall out of fast isel after selecting this.
3718-
const TargetRegisterClass *DstClass = TLI.getRegClassFor(DstVT);
3719-
Register ResultReg = createResultReg(DstClass);
3720-
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
3721-
TII.get(TargetOpcode::COPY), ResultReg).addReg(Reg);
3722-
3723-
updateValueMap(I, ResultReg);
3724-
return true;
3725-
}
3727+
case Instruction::BitCast:
3728+
return X86SelectBitCast(I);
37263729
}
37273730

37283731
return false;

0 commit comments

Comments
 (0)