@@ -7132,7 +7132,7 @@ static void updateOperandRegConstraints(MachineFunction &MF,
7132
7132
}
7133
7133
}
7134
7134
7135
- static MachineInstr *FuseTwoAddrInst (MachineFunction &MF, unsigned Opcode,
7135
+ static MachineInstr *fuseTwoAddrInst (MachineFunction &MF, unsigned Opcode,
7136
7136
ArrayRef<MachineOperand> MOs,
7137
7137
MachineBasicBlock::iterator InsertPt,
7138
7138
MachineInstr &MI,
@@ -7161,7 +7161,7 @@ static MachineInstr *FuseTwoAddrInst(MachineFunction &MF, unsigned Opcode,
7161
7161
return MIB;
7162
7162
}
7163
7163
7164
- static MachineInstr *FuseInst (MachineFunction &MF, unsigned Opcode,
7164
+ static MachineInstr *fuseInst (MachineFunction &MF, unsigned Opcode,
7165
7165
unsigned OpNo, ArrayRef<MachineOperand> MOs,
7166
7166
MachineBasicBlock::iterator InsertPt,
7167
7167
MachineInstr &MI, const TargetInstrInfo &TII,
@@ -7231,7 +7231,7 @@ MachineInstr *X86InstrInfo::foldMemoryOperandCustom(
7231
7231
: (MI.getOpcode () == X86::VINSERTPSrr) ? X86::VINSERTPSrm
7232
7232
: X86::INSERTPSrm;
7233
7233
MachineInstr *NewMI =
7234
- FuseInst (MF, NewOpCode, OpNum, MOs, InsertPt, MI, *this , PtrOffset);
7234
+ fuseInst (MF, NewOpCode, OpNum, MOs, InsertPt, MI, *this , PtrOffset);
7235
7235
NewMI->getOperand (NewMI->getNumOperands () - 1 ).setImm (NewImm);
7236
7236
return NewMI;
7237
7237
}
@@ -7253,7 +7253,7 @@ MachineInstr *X86InstrInfo::foldMemoryOperandCustom(
7253
7253
: (MI.getOpcode () == X86::VMOVHLPSrr) ? X86::VMOVLPSrm
7254
7254
: X86::MOVLPSrm;
7255
7255
MachineInstr *NewMI =
7256
- FuseInst (MF, NewOpCode, OpNum, MOs, InsertPt, MI, *this , 8 );
7256
+ fuseInst (MF, NewOpCode, OpNum, MOs, InsertPt, MI, *this , 8 );
7257
7257
return NewMI;
7258
7258
}
7259
7259
}
@@ -7268,7 +7268,7 @@ MachineInstr *X86InstrInfo::foldMemoryOperandCustom(
7268
7268
unsigned RCSize = TRI.getRegSizeInBits (*RC) / 8 ;
7269
7269
if ((Size == 0 || Size >= 16 ) && RCSize >= 16 && Alignment < Align (16 )) {
7270
7270
MachineInstr *NewMI =
7271
- FuseInst (MF, X86::MOVHPDrm, OpNum, MOs, InsertPt, MI, *this );
7271
+ fuseInst (MF, X86::MOVHPDrm, OpNum, MOs, InsertPt, MI, *this );
7272
7272
return NewMI;
7273
7273
}
7274
7274
}
@@ -7328,30 +7328,30 @@ MachineInstr *X86InstrInfo::foldMemoryOperandImpl(
7328
7328
ArrayRef<MachineOperand> MOs, MachineBasicBlock::iterator InsertPt,
7329
7329
unsigned Size , Align Alignment, bool AllowCommute) const {
7330
7330
bool isSlowTwoMemOps = Subtarget.slowTwoMemOps ();
7331
- bool isTwoAddrFold = false ;
7331
+ unsigned Opc = MI. getOpcode () ;
7332
7332
7333
7333
// For CPUs that favor the register form of a call or push,
7334
7334
// do not fold loads into calls or pushes, unless optimizing for size
7335
7335
// aggressively.
7336
7336
if (isSlowTwoMemOps && !MF.getFunction ().hasMinSize () &&
7337
- (MI.getOpcode () == X86::CALL32r || MI.getOpcode () == X86::CALL64r ||
7338
- MI.getOpcode () == X86::PUSH16r || MI.getOpcode () == X86::PUSH32r ||
7339
- MI.getOpcode () == X86::PUSH64r))
7337
+ (Opc == X86::CALL32r || Opc == X86::CALL64r || Opc == X86::PUSH16r ||
7338
+ Opc == X86::PUSH32r || Opc == X86::PUSH64r))
7340
7339
return nullptr ;
7341
7340
7342
7341
// Avoid partial and undef register update stalls unless optimizing for size.
7343
7342
if (!MF.getFunction ().hasOptSize () &&
7344
- (hasPartialRegUpdate (MI. getOpcode () , Subtarget, /* ForLoadFold*/ true ) ||
7343
+ (hasPartialRegUpdate (Opc , Subtarget, /* ForLoadFold*/ true ) ||
7345
7344
shouldPreventUndefRegUpdateMemFold (MF, MI)))
7346
7345
return nullptr ;
7347
7346
7348
7347
unsigned NumOps = MI.getDesc ().getNumOperands ();
7349
- bool isTwoAddr =
7350
- NumOps > 1 && MI.getDesc ().getOperandConstraint (1 , MCOI::TIED_TO) != -1 ;
7348
+ bool IsTwoAddr = NumOps > 1 && OpNum < 2 && MI.getOperand (0 ).isReg () &&
7349
+ MI.getOperand (1 ).isReg () &&
7350
+ MI.getOperand (0 ).getReg () == MI.getOperand (1 ).getReg ();
7351
7351
7352
7352
// FIXME: AsmPrinter doesn't know how to handle
7353
7353
// X86II::MO_GOT_ABSOLUTE_ADDRESS after folding.
7354
- if (MI. getOpcode () == X86::ADD32ri &&
7354
+ if (Opc == X86::ADD32ri &&
7355
7355
MI.getOperand (2 ).getTargetFlags () == X86II::MO_GOT_ABSOLUTE_ADDRESS)
7356
7356
return nullptr ;
7357
7357
@@ -7360,44 +7360,31 @@ MachineInstr *X86InstrInfo::foldMemoryOperandImpl(
7360
7360
// instructions.
7361
7361
if (MOs.size () == X86::AddrNumOperands &&
7362
7362
MOs[X86::AddrDisp].getTargetFlags () == X86II::MO_GOTTPOFF &&
7363
- MI. getOpcode () != X86::ADD64rr)
7363
+ Opc != X86::ADD64rr)
7364
7364
return nullptr ;
7365
7365
7366
7366
// Don't fold loads into indirect calls that need a KCFI check as we'll
7367
7367
// have to unfold these in X86TargetLowering::EmitKCFICheck anyway.
7368
7368
if (MI.isCall () && MI.getCFIType ())
7369
7369
return nullptr ;
7370
7370
7371
- MachineInstr *NewMI = nullptr ;
7372
-
7373
7371
// Attempt to fold any custom cases we have.
7374
- if (MachineInstr *CustomMI = foldMemoryOperandCustom (
7375
- MF, MI, OpNum, MOs, InsertPt, Size , Alignment))
7372
+ if (auto *CustomMI = foldMemoryOperandCustom (MF, MI, OpNum, MOs, InsertPt,
7373
+ Size , Alignment))
7376
7374
return CustomMI;
7377
7375
7378
- const X86FoldTableEntry *I = nullptr ;
7376
+ if (Opc == X86::MOV32r0)
7377
+ if (auto *NewMI = MakeM0Inst (*this , X86::MOV32mi, MOs, InsertPt, MI))
7378
+ return NewMI;
7379
7379
7380
7380
// Folding a memory location into the two-address part of a two-address
7381
7381
// instruction is different than folding it other places. It requires
7382
7382
// replacing the *two* registers with the memory location.
7383
- if (isTwoAddr && NumOps >= 2 && OpNum < 2 && MI.getOperand (0 ).isReg () &&
7384
- MI.getOperand (1 ).isReg () &&
7385
- MI.getOperand (0 ).getReg () == MI.getOperand (1 ).getReg ()) {
7386
- I = lookupTwoAddrFoldTable (MI.getOpcode ());
7387
- isTwoAddrFold = true ;
7388
- } else {
7389
- if (OpNum == 0 ) {
7390
- if (MI.getOpcode () == X86::MOV32r0) {
7391
- NewMI = MakeM0Inst (*this , X86::MOV32mi, MOs, InsertPt, MI);
7392
- if (NewMI)
7393
- return NewMI;
7394
- }
7395
- }
7396
-
7397
- I = lookupFoldTable (MI.getOpcode (), OpNum);
7398
- }
7383
+ const X86FoldTableEntry *I =
7384
+ IsTwoAddr ? lookupTwoAddrFoldTable (Opc) : lookupFoldTable (Opc, OpNum);
7399
7385
7400
- if (I != nullptr ) {
7386
+ MachineInstr *NewMI = nullptr ;
7387
+ if (I) {
7401
7388
unsigned Opcode = I->DstOp ;
7402
7389
if (Alignment <
7403
7390
Align (1ULL << ((I->Flags & TB_ALIGN_MASK) >> TB_ALIGN_SHIFT)))
@@ -7428,10 +7415,8 @@ MachineInstr *X86InstrInfo::foldMemoryOperandImpl(
7428
7415
return nullptr ;
7429
7416
}
7430
7417
7431
- if (isTwoAddrFold)
7432
- NewMI = FuseTwoAddrInst (MF, Opcode, MOs, InsertPt, MI, *this );
7433
- else
7434
- NewMI = FuseInst (MF, Opcode, OpNum, MOs, InsertPt, MI, *this );
7418
+ NewMI = IsTwoAddr ? fuseTwoAddrInst (MF, Opcode, MOs, InsertPt, MI, *this )
7419
+ : fuseInst (MF, Opcode, OpNum, MOs, InsertPt, MI, *this );
7435
7420
7436
7421
if (NarrowToMOV32rm) {
7437
7422
// If this is the special case where we use a MOV32rm to load a 32-bit
@@ -8231,7 +8216,7 @@ X86InstrInfo::foldMemoryBroadcast(MachineFunction &MF, MachineInstr &MI,
8231
8216
8232
8217
if (auto *I = lookupBroadcastFoldTable (MI.getOpcode (), OpNum))
8233
8218
return matchBroadcastSize (*I, BitsSize)
8234
- ? FuseInst (MF, I->DstOp , OpNum, MOs, InsertPt, MI, *this )
8219
+ ? fuseInst (MF, I->DstOp , OpNum, MOs, InsertPt, MI, *this )
8235
8220
: nullptr ;
8236
8221
8237
8222
if (AllowCommute) {
0 commit comments