Skip to content

Commit ff040ec

Browse files
committed
[FastISel] Reuse register for bitcast that does not change MVT
The current FastISel code reuses the register for a bitcast that doesn't change the IR type, but uses a reg-to-reg copy if it changes the IR type without changing the MVT. However, we can simply reuse the register in that case as well. In particular, this avoids unnecessary reg-to-reg copies for pointer bitcasts. This was found while inspecting O0 codegen differences between typed and opaque pointers. Differential Revision: https://reviews.llvm.org/D119432
1 parent d593cf7 commit ff040ec

File tree

5 files changed

+125
-195
lines changed

5 files changed

+125
-195
lines changed

llvm/lib/CodeGen/SelectionDAG/FastISel.cpp

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

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

1434-
// First, try to perform the bitcast by inserting a reg-reg copy.
1435-
Register ResultReg;
1424+
// If the bitcast doesn't change the type, just use the operand value.
14361425
if (SrcVT == DstVT) {
1437-
ResultReg = createResultReg(TLI.getRegClassFor(DstVT));
1438-
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1439-
TII.get(TargetOpcode::COPY), ResultReg).addReg(Op0);
1426+
updateValueMap(I, Op0);
1427+
return true;
14401428
}
14411429

1442-
// If the reg-reg copy failed, select a BITCAST opcode.
1443-
if (!ResultReg)
1444-
ResultReg = fastEmit_r(SrcVT, DstVT, ISD::BITCAST, Op0);
1445-
1430+
// Otherwise, select a BITCAST opcode.
1431+
Register ResultReg = fastEmit_r(SrcVT, DstVT, ISD::BITCAST, Op0);
14461432
if (!ResultReg)
14471433
return false;
14481434

0 commit comments

Comments
 (0)