Skip to content

Commit 6625103

Browse files
authored
Merge pull request #4672 from bnbarham/revert-reuse-register
[stable/20220421] Revert "[FastISel] Reuse register for bitcast that does not change MVT"
2 parents 1c3b617 + 9db1ebf commit 6625103

File tree

5 files changed

+198
-128
lines changed

5 files changed

+198
-128
lines changed

llvm/lib/CodeGen/SelectionDAG/FastISel.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,16 @@ bool FastISel::selectCast(const User *I, unsigned Opcode) {
14061406
}
14071407

14081408
bool FastISel::selectBitCast(const User *I) {
1409+
// If the bitcast doesn't change the type, just use the operand value.
1410+
if (I->getType() == I->getOperand(0)->getType()) {
1411+
Register Reg = getRegForValue(I->getOperand(0));
1412+
if (!Reg)
1413+
return false;
1414+
updateValueMap(I, Reg);
1415+
return true;
1416+
}
1417+
1418+
// Bitcasts of other values become reg-reg copies or BITCAST operators.
14091419
EVT SrcEVT = TLI.getValueType(DL, I->getOperand(0)->getType());
14101420
EVT DstEVT = TLI.getValueType(DL, I->getType());
14111421
if (SrcEVT == MVT::Other || DstEVT == MVT::Other ||
@@ -1419,14 +1429,18 @@ bool FastISel::selectBitCast(const User *I) {
14191429
if (!Op0) // Unhandled operand. Halt "fast" selection and bail.
14201430
return false;
14211431

1422-
// If the bitcast doesn't change the type, just use the operand value.
1432+
// First, try to perform the bitcast by inserting a reg-reg copy.
1433+
Register ResultReg;
14231434
if (SrcVT == DstVT) {
1424-
updateValueMap(I, Op0);
1425-
return true;
1435+
ResultReg = createResultReg(TLI.getRegClassFor(DstVT));
1436+
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1437+
TII.get(TargetOpcode::COPY), ResultReg).addReg(Op0);
14261438
}
14271439

1428-
// Otherwise, select a BITCAST opcode.
1429-
Register ResultReg = fastEmit_r(SrcVT, DstVT, ISD::BITCAST, Op0);
1440+
// If the reg-reg copy failed, select a BITCAST opcode.
1441+
if (!ResultReg)
1442+
ResultReg = fastEmit_r(SrcVT, DstVT, ISD::BITCAST, Op0);
1443+
14301444
if (!ResultReg)
14311445
return false;
14321446

0 commit comments

Comments
 (0)