@@ -1406,6 +1406,16 @@ bool FastISel::selectCast(const User *I, unsigned Opcode) {
1406
1406
}
1407
1407
1408
1408
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.
1409
1419
EVT SrcEVT = TLI.getValueType (DL, I->getOperand (0 )->getType ());
1410
1420
EVT DstEVT = TLI.getValueType (DL, I->getType ());
1411
1421
if (SrcEVT == MVT::Other || DstEVT == MVT::Other ||
@@ -1419,14 +1429,18 @@ bool FastISel::selectBitCast(const User *I) {
1419
1429
if (!Op0) // Unhandled operand. Halt "fast" selection and bail.
1420
1430
return false ;
1421
1431
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;
1423
1434
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);
1426
1438
}
1427
1439
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
+
1430
1444
if (!ResultReg)
1431
1445
return false ;
1432
1446
0 commit comments