Skip to content

Commit c82a645

Browse files
committed
[X86][NFC] Simplify the code for memory fold
1 parent 3b76b86 commit c82a645

File tree

2 files changed

+11
-25
lines changed

2 files changed

+11
-25
lines changed

llvm/lib/Target/X86/X86InstrInfo.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7309,10 +7309,6 @@ MachineInstr *X86InstrInfo::foldMemoryOperandImpl(
73097309

73107310
if (I != nullptr) {
73117311
unsigned Opcode = I->DstOp;
7312-
bool FoldedLoad =
7313-
isTwoAddrFold || (OpNum == 0 && I->Flags & TB_FOLDED_LOAD) || OpNum > 0;
7314-
bool FoldedStore =
7315-
isTwoAddrFold || (OpNum == 0 && I->Flags & TB_FOLDED_STORE);
73167312
if (Alignment <
73177313
Align(1ULL << ((I->Flags & TB_ALIGN_MASK) >> TB_ALIGN_SHIFT)))
73187314
return nullptr;
@@ -7324,7 +7320,7 @@ MachineInstr *X86InstrInfo::foldMemoryOperandImpl(
73247320
// Check if it's safe to fold the load. If the size of the object is
73257321
// narrower than the load width, then it's not.
73267322
// FIXME: Allow scalar intrinsic instructions like ADDSSrm_Int.
7327-
if (FoldedLoad && Size < RCSize) {
7323+
if ((I->Flags & TB_FOLDED_LOAD) && Size < RCSize) {
73287324
// If this is a 64-bit load, but the spill slot is 32, then we can do
73297325
// a 32-bit load which is implicitly zero-extended. This likely is
73307326
// due to live interval analysis remat'ing a load from stack slot.
@@ -7338,7 +7334,7 @@ MachineInstr *X86InstrInfo::foldMemoryOperandImpl(
73387334
// For stores, make sure the size of the object is equal to the size of
73397335
// the store. If the object is larger, the extra bits would be garbage. If
73407336
// the object is smaller we might overwrite another object or fault.
7341-
if (FoldedStore && Size != RCSize)
7337+
if ((I->Flags & TB_FOLDED_STORE) && Size != RCSize)
73427338
return nullptr;
73437339
}
73447340

llvm/utils/TableGen/X86FoldTablesEmitter.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,6 @@ void X86FoldTablesEmitter::addEntryWithFlags(FoldTable &Table,
452452
"Override entry unexpectedly");
453453
X86FoldTableEntry Result = X86FoldTableEntry(RegInst, MemInst);
454454
Record *RegRec = RegInst->TheDef;
455-
Record *MemRec = MemInst->TheDef;
456-
457455
Result.NoReverse = S & TB_NO_REVERSE;
458456
Result.NoForward = S & TB_NO_FORWARD;
459457
Result.FoldLoad = S & TB_FOLDED_LOAD;
@@ -464,21 +462,6 @@ void X86FoldTablesEmitter::addEntryWithFlags(FoldTable &Table,
464462
return;
465463
}
466464

467-
// Only table0 entries should explicitly specify a load or store flag.
468-
if (&Table == &Table0) {
469-
unsigned MemInOpsNum = MemRec->getValueAsDag("InOperandList")->getNumArgs();
470-
unsigned RegInOpsNum = RegRec->getValueAsDag("InOperandList")->getNumArgs();
471-
// If the instruction writes to the folded operand, it will appear as an
472-
// output in the register form instruction and as an input in the memory
473-
// form instruction.
474-
// If the instruction reads from the folded operand, it well appear as in
475-
// input in both forms.
476-
if (MemInOpsNum == RegInOpsNum)
477-
Result.FoldLoad = true;
478-
else
479-
Result.FoldStore = true;
480-
}
481-
482465
Record *RegOpRec = RegInst->Operands[FoldedIdx].Rec;
483466
Record *MemOpRec = MemInst->Operands[FoldedIdx].Rec;
484467

@@ -575,6 +558,11 @@ void X86FoldTablesEmitter::updateTables(const CodeGenInstruction *RegInst,
575558
return;
576559
}
577560

561+
// Only table0 entries should explicitly specify a load or store flag.
562+
// If the instruction writes to the folded operand, it will appear as
563+
// an output in the register form instruction and as an input in the
564+
// memory form instruction. If the instruction reads from the folded
565+
// operand, it will appear as in input in both forms.
578566
if (MemInSize == RegInSize && MemOutSize == RegOutSize) {
579567
// Load-Folding cases.
580568
// If the i'th register form operand is a register and the i'th memory form
@@ -590,7 +578,8 @@ void X86FoldTablesEmitter::updateTables(const CodeGenInstruction *RegInst,
590578
switch (I) {
591579
case 0:
592580
assert(!IsBroadcast && "BroadcastTable0 needs to be added");
593-
addEntryWithFlags(Table0, RegInst, MemInst, S, 0, IsManual);
581+
addEntryWithFlags(Table0, RegInst, MemInst, S | TB_FOLDED_LOAD, 0,
582+
IsManual);
594583
return;
595584
case 1:
596585
IsBroadcast
@@ -628,7 +617,8 @@ void X86FoldTablesEmitter::updateTables(const CodeGenInstruction *RegInst,
628617
if (isRegisterOperand(RegOpRec) && isMemoryOperand(MemOpRec) &&
629618
getRegOperandSize(RegOpRec) == getMemOperandSize(MemOpRec)) {
630619
assert(!IsBroadcast && "Store can not be broadcast");
631-
addEntryWithFlags(Table0, RegInst, MemInst, S, 0, IsManual);
620+
addEntryWithFlags(Table0, RegInst, MemInst, S | TB_FOLDED_STORE, 0,
621+
IsManual);
632622
}
633623
}
634624
}

0 commit comments

Comments
 (0)