Skip to content

Commit 757a2f1

Browse files
committedJun 13, 2019
[X86] Use fresh MemOps when emitting VAARG64
Previously it copied over MachineMemOperands verbatim which caused MOV32rm to have store flags set, and MOV32mr to have load flags set. This fixes some assertions being thrown with EXPENSIVE_CHECKS on. Committed on behalf of @luke (Luke Lau) Differential Revision: https://reviews.llvm.org/D62726 llvm-svn: 363268
1 parent 1278a19 commit 757a2f1

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed
 

‎llvm/lib/Target/X86/X86ISelLowering.cpp

+15-8
Original file line numberDiff line numberDiff line change
@@ -28728,10 +28728,18 @@ X86TargetLowering::EmitVAARG64WithCustomInserter(MachineInstr &MI,
2872828728
unsigned ArgMode = MI.getOperand(7).getImm();
2872928729
unsigned Align = MI.getOperand(8).getImm();
2873028730

28731+
MachineFunction *MF = MBB->getParent();
28732+
2873128733
// Memory Reference
2873228734
assert(MI.hasOneMemOperand() && "Expected VAARG_64 to have one memoperand");
28733-
SmallVector<MachineMemOperand *, 1> MMOs(MI.memoperands_begin(),
28734-
MI.memoperands_end());
28735+
28736+
MachineMemOperand *OldMMO = MI.memoperands().front();
28737+
28738+
// Clone the MMO into two separate MMOs for loading and storing
28739+
MachineMemOperand *LoadOnlyMMO = MF->getMachineMemOperand(
28740+
OldMMO, OldMMO->getFlags() & ~MachineMemOperand::MOStore);
28741+
MachineMemOperand *StoreOnlyMMO = MF->getMachineMemOperand(
28742+
OldMMO, OldMMO->getFlags() & ~MachineMemOperand::MOLoad);
2873528743

2873628744
// Machine Information
2873728745
const TargetInstrInfo *TII = Subtarget.getInstrInfo();
@@ -28796,7 +28804,6 @@ X86TargetLowering::EmitVAARG64WithCustomInserter(MachineInstr &MI,
2879628804
OverflowDestReg = MRI.createVirtualRegister(AddrRegClass);
2879728805

2879828806
const BasicBlock *LLVM_BB = MBB->getBasicBlock();
28799-
MachineFunction *MF = MBB->getParent();
2880028807
overflowMBB = MF->CreateMachineBasicBlock(LLVM_BB);
2880128808
offsetMBB = MF->CreateMachineBasicBlock(LLVM_BB);
2880228809
endMBB = MF->CreateMachineBasicBlock(LLVM_BB);
@@ -28829,7 +28836,7 @@ X86TargetLowering::EmitVAARG64WithCustomInserter(MachineInstr &MI,
2882928836
.add(Index)
2883028837
.addDisp(Disp, UseFPOffset ? 4 : 0)
2883128838
.add(Segment)
28832-
.setMemRefs(MMOs);
28839+
.setMemRefs(LoadOnlyMMO);
2883328840

2883428841
// Check if there is enough room left to pull this argument.
2883528842
BuildMI(thisMBB, DL, TII->get(X86::CMP32ri))
@@ -28854,7 +28861,7 @@ X86TargetLowering::EmitVAARG64WithCustomInserter(MachineInstr &MI,
2885428861
.add(Index)
2885528862
.addDisp(Disp, 16)
2885628863
.add(Segment)
28857-
.setMemRefs(MMOs);
28864+
.setMemRefs(LoadOnlyMMO);
2885828865

2885928866
// Zero-extend the offset
2886028867
unsigned OffsetReg64 = MRI.createVirtualRegister(AddrRegClass);
@@ -28882,7 +28889,7 @@ X86TargetLowering::EmitVAARG64WithCustomInserter(MachineInstr &MI,
2888228889
.addDisp(Disp, UseFPOffset ? 4 : 0)
2888328890
.add(Segment)
2888428891
.addReg(NextOffsetReg)
28885-
.setMemRefs(MMOs);
28892+
.setMemRefs(StoreOnlyMMO);
2888628893

2888728894
// Jump to endMBB
2888828895
BuildMI(offsetMBB, DL, TII->get(X86::JMP_1))
@@ -28901,7 +28908,7 @@ X86TargetLowering::EmitVAARG64WithCustomInserter(MachineInstr &MI,
2890128908
.add(Index)
2890228909
.addDisp(Disp, 8)
2890328910
.add(Segment)
28904-
.setMemRefs(MMOs);
28911+
.setMemRefs(LoadOnlyMMO);
2890528912

2890628913
// If we need to align it, do so. Otherwise, just copy the address
2890728914
// to OverflowDestReg.
@@ -28938,7 +28945,7 @@ X86TargetLowering::EmitVAARG64WithCustomInserter(MachineInstr &MI,
2893828945
.addDisp(Disp, 8)
2893928946
.add(Segment)
2894028947
.addReg(NextAddrReg)
28941-
.setMemRefs(MMOs);
28948+
.setMemRefs(StoreOnlyMMO);
2894228949

2894328950
// If we branched, emit the PHI to the front of endMBB.
2894428951
if (offsetMBB) {

0 commit comments

Comments
 (0)
Please sign in to comment.