Skip to content

Commit 0bb243e

Browse files
author
git apple-llvm automerger
committed
Merge commit '8a438096ffa4' from llvm.org/release/11.x into apple/stable/20200714
2 parents f3f87cb + 8a43809 commit 0bb243e

File tree

7 files changed

+62
-207
lines changed

7 files changed

+62
-207
lines changed

llvm/lib/CodeGen/TwoAddressInstructionPass.cpp

Lines changed: 5 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ STATISTIC(NumTwoAddressInstrs, "Number of two-address instructions");
7070
STATISTIC(NumCommuted , "Number of instructions commuted to coalesce");
7171
STATISTIC(NumAggrCommuted , "Number of instructions aggressively commuted");
7272
STATISTIC(NumConvertedTo3Addr, "Number of instructions promoted to 3-address");
73-
STATISTIC(Num3AddrSunk, "Number of 3-address instructions sunk");
7473
STATISTIC(NumReSchedUps, "Number of instructions re-scheduled up");
7574
STATISTIC(NumReSchedDowns, "Number of instructions re-scheduled down");
7675

@@ -109,10 +108,6 @@ class TwoAddressInstructionPass : public MachineFunctionPass {
109108
// Set of already processed instructions in the current block.
110109
SmallPtrSet<MachineInstr*, 8> Processed;
111110

112-
// Set of instructions converted to three-address by target and then sunk
113-
// down current basic block.
114-
SmallPtrSet<MachineInstr*, 8> SunkInstrs;
115-
116111
// A map from virtual registers to physical registers which are likely targets
117112
// to be coalesced to due to copies from physical registers to virtual
118113
// registers. e.g. v1024 = move r0.
@@ -123,9 +118,6 @@ class TwoAddressInstructionPass : public MachineFunctionPass {
123118
// registers. e.g. r1 = move v1024.
124119
DenseMap<unsigned, unsigned> DstRegMap;
125120

126-
bool sink3AddrInstruction(MachineInstr *MI, unsigned Reg,
127-
MachineBasicBlock::iterator OldPos);
128-
129121
bool isRevCopyChain(unsigned FromReg, unsigned ToReg, int Maxlen);
130122

131123
bool noUseAfterLastDef(unsigned Reg, unsigned Dist, unsigned &LastDef);
@@ -209,136 +201,6 @@ INITIALIZE_PASS_END(TwoAddressInstructionPass, DEBUG_TYPE,
209201

210202
static bool isPlainlyKilled(MachineInstr *MI, unsigned Reg, LiveIntervals *LIS);
211203

212-
/// A two-address instruction has been converted to a three-address instruction
213-
/// to avoid clobbering a register. Try to sink it past the instruction that
214-
/// would kill the above mentioned register to reduce register pressure.
215-
bool TwoAddressInstructionPass::
216-
sink3AddrInstruction(MachineInstr *MI, unsigned SavedReg,
217-
MachineBasicBlock::iterator OldPos) {
218-
// FIXME: Shouldn't we be trying to do this before we three-addressify the
219-
// instruction? After this transformation is done, we no longer need
220-
// the instruction to be in three-address form.
221-
222-
// Check if it's safe to move this instruction.
223-
bool SeenStore = true; // Be conservative.
224-
if (!MI->isSafeToMove(AA, SeenStore))
225-
return false;
226-
227-
unsigned DefReg = 0;
228-
SmallSet<unsigned, 4> UseRegs;
229-
230-
for (const MachineOperand &MO : MI->operands()) {
231-
if (!MO.isReg())
232-
continue;
233-
Register MOReg = MO.getReg();
234-
if (!MOReg)
235-
continue;
236-
if (MO.isUse() && MOReg != SavedReg)
237-
UseRegs.insert(MO.getReg());
238-
if (!MO.isDef())
239-
continue;
240-
if (MO.isImplicit())
241-
// Don't try to move it if it implicitly defines a register.
242-
return false;
243-
if (DefReg)
244-
// For now, don't move any instructions that define multiple registers.
245-
return false;
246-
DefReg = MO.getReg();
247-
}
248-
249-
// Find the instruction that kills SavedReg.
250-
MachineInstr *KillMI = nullptr;
251-
if (LIS) {
252-
LiveInterval &LI = LIS->getInterval(SavedReg);
253-
assert(LI.end() != LI.begin() &&
254-
"Reg should not have empty live interval.");
255-
256-
SlotIndex MBBEndIdx = LIS->getMBBEndIdx(MBB).getPrevSlot();
257-
LiveInterval::const_iterator I = LI.find(MBBEndIdx);
258-
if (I != LI.end() && I->start < MBBEndIdx)
259-
return false;
260-
261-
--I;
262-
KillMI = LIS->getInstructionFromIndex(I->end);
263-
}
264-
if (!KillMI) {
265-
for (MachineOperand &UseMO : MRI->use_nodbg_operands(SavedReg)) {
266-
if (!UseMO.isKill())
267-
continue;
268-
KillMI = UseMO.getParent();
269-
break;
270-
}
271-
}
272-
273-
// If we find the instruction that kills SavedReg, and it is in an
274-
// appropriate location, we can try to sink the current instruction
275-
// past it.
276-
if (!KillMI || KillMI->getParent() != MBB || KillMI == MI ||
277-
MachineBasicBlock::iterator(KillMI) == OldPos || KillMI->isTerminator())
278-
return false;
279-
280-
// If any of the definitions are used by another instruction between the
281-
// position and the kill use, then it's not safe to sink it.
282-
//
283-
// FIXME: This can be sped up if there is an easy way to query whether an
284-
// instruction is before or after another instruction. Then we can use
285-
// MachineRegisterInfo def / use instead.
286-
MachineOperand *KillMO = nullptr;
287-
MachineBasicBlock::iterator KillPos = KillMI;
288-
++KillPos;
289-
290-
unsigned NumVisited = 0;
291-
for (MachineInstr &OtherMI : make_range(std::next(OldPos), KillPos)) {
292-
// Debug instructions cannot be counted against the limit.
293-
if (OtherMI.isDebugInstr())
294-
continue;
295-
if (NumVisited > 30) // FIXME: Arbitrary limit to reduce compile time cost.
296-
return false;
297-
++NumVisited;
298-
for (unsigned i = 0, e = OtherMI.getNumOperands(); i != e; ++i) {
299-
MachineOperand &MO = OtherMI.getOperand(i);
300-
if (!MO.isReg())
301-
continue;
302-
Register MOReg = MO.getReg();
303-
if (!MOReg)
304-
continue;
305-
if (DefReg == MOReg)
306-
return false;
307-
308-
if (MO.isKill() || (LIS && isPlainlyKilled(&OtherMI, MOReg, LIS))) {
309-
if (&OtherMI == KillMI && MOReg == SavedReg)
310-
// Save the operand that kills the register. We want to unset the kill
311-
// marker if we can sink MI past it.
312-
KillMO = &MO;
313-
else if (UseRegs.count(MOReg))
314-
// One of the uses is killed before the destination.
315-
return false;
316-
}
317-
}
318-
}
319-
assert(KillMO && "Didn't find kill");
320-
321-
if (!LIS) {
322-
// Update kill and LV information.
323-
KillMO->setIsKill(false);
324-
KillMO = MI->findRegisterUseOperand(SavedReg, false, TRI);
325-
KillMO->setIsKill(true);
326-
327-
if (LV)
328-
LV->replaceKillInstruction(SavedReg, *KillMI, *MI);
329-
}
330-
331-
// Move instruction to its destination.
332-
MBB->remove(MI);
333-
MBB->insert(KillPos, MI);
334-
335-
if (LIS)
336-
LIS->handleMove(*MI);
337-
338-
++Num3AddrSunk;
339-
return true;
340-
}
341-
342204
/// Return the MachineInstr* if it is the single def of the Reg in current BB.
343205
static MachineInstr *getSingleDef(unsigned Reg, MachineBasicBlock *BB,
344206
const MachineRegisterInfo *MRI) {
@@ -740,26 +602,15 @@ TwoAddressInstructionPass::convertInstTo3Addr(MachineBasicBlock::iterator &mi,
740602

741603
LLVM_DEBUG(dbgs() << "2addr: CONVERTING 2-ADDR: " << *mi);
742604
LLVM_DEBUG(dbgs() << "2addr: TO 3-ADDR: " << *NewMI);
743-
bool Sunk = false;
744605

745606
if (LIS)
746607
LIS->ReplaceMachineInstrInMaps(*mi, *NewMI);
747608

748-
if (NewMI->findRegisterUseOperand(RegB, false, TRI))
749-
// FIXME: Temporary workaround. If the new instruction doesn't
750-
// uses RegB, convertToThreeAddress must have created more
751-
// then one instruction.
752-
Sunk = sink3AddrInstruction(NewMI, RegB, mi);
753-
754609
MBB->erase(mi); // Nuke the old inst.
755610

756-
if (!Sunk) {
757-
DistanceMap.insert(std::make_pair(NewMI, Dist));
758-
mi = NewMI;
759-
nmi = std::next(mi);
760-
}
761-
else
762-
SunkInstrs.insert(NewMI);
611+
DistanceMap.insert(std::make_pair(NewMI, Dist));
612+
mi = NewMI;
613+
nmi = std::next(mi);
763614

764615
// Update source and destination register maps.
765616
SrcRegMap.erase(RegA);
@@ -1700,13 +1551,11 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &Func) {
17001551
SrcRegMap.clear();
17011552
DstRegMap.clear();
17021553
Processed.clear();
1703-
SunkInstrs.clear();
17041554
for (MachineBasicBlock::iterator mi = MBB->begin(), me = MBB->end();
17051555
mi != me; ) {
17061556
MachineBasicBlock::iterator nmi = std::next(mi);
1707-
// Don't revisit an instruction previously converted by target. It may
1708-
// contain undef register operands (%noreg), which are not handled.
1709-
if (mi->isDebugInstr() || SunkInstrs.count(&*mi)) {
1557+
// Skip debug instructions.
1558+
if (mi->isDebugInstr()) {
17101559
mi = nmi;
17111560
continue;
17121561
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
3+
4+
;; Verify that the machine instructions generated from the first
5+
;; getelementptr don't get sunk below the callbr. (Reduced from a bug
6+
;; report.)
7+
8+
%struct1 = type { i8*, i32 }
9+
10+
define void @klist_dec_and_del(%struct1*) {
11+
; CHECK-LABEL: klist_dec_and_del:
12+
; CHECK: # %bb.0:
13+
; CHECK-NEXT: leaq 8(%rdi), %rax
14+
; CHECK-NEXT: #APP
15+
; CHECK-NEXT: # 8(%rdi) .Ltmp0
16+
; CHECK-NEXT: #NO_APP
17+
; CHECK-NEXT: # %bb.2:
18+
; CHECK-NEXT: retq
19+
; CHECK-NEXT: .Ltmp0: # Block address taken
20+
; CHECK-NEXT: .LBB0_1:
21+
; CHECK-NEXT: movq $0, -8(%rax)
22+
; CHECK-NEXT: retq
23+
%2 = getelementptr inbounds %struct1, %struct1* %0, i64 0, i32 1
24+
callbr void asm sideeffect "# $0 $1", "*m,X,~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %2, i8* blockaddress(@klist_dec_and_del, %3))
25+
to label %6 [label %3]
26+
27+
3:
28+
%4 = getelementptr i32, i32* %2, i64 -2
29+
%5 = bitcast i32* %4 to i8**
30+
store i8* null, i8** %5, align 8
31+
br label %6
32+
33+
6:
34+
ret void
35+
}

llvm/test/CodeGen/X86/masked-iv-unsafe.ll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,9 @@ return:
402402
define void @another_count_down_signed(double* %d, i64 %n) nounwind {
403403
; CHECK-LABEL: another_count_down_signed:
404404
; CHECK: # %bb.0: # %entry
405-
; CHECK-NEXT: movq %rsi, %rax
406-
; CHECK-NEXT: shlq $24, %rax
407-
; CHECK-NEXT: leaq -10(%rsi), %rcx
405+
; CHECK-NEXT: leaq -10(%rsi), %rax
406+
; CHECK-NEXT: movq %rsi, %rcx
407+
; CHECK-NEXT: shlq $24, %rcx
408408
; CHECK-NEXT: shlq $8, %rsi
409409
; CHECK-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
410410
; CHECK-NEXT: movsd {{.*#+}} xmm1 = mem[0],zero
@@ -417,17 +417,17 @@ define void @another_count_down_signed(double* %d, i64 %n) nounwind {
417417
; CHECK-NEXT: movsd {{.*#+}} xmm3 = mem[0],zero
418418
; CHECK-NEXT: mulsd %xmm0, %xmm3
419419
; CHECK-NEXT: movsd %xmm3, (%rdi,%rdx,8)
420-
; CHECK-NEXT: movq %rax, %rdx
420+
; CHECK-NEXT: movq %rcx, %rdx
421421
; CHECK-NEXT: sarq $24, %rdx
422422
; CHECK-NEXT: movsd {{.*#+}} xmm3 = mem[0],zero
423423
; CHECK-NEXT: mulsd %xmm1, %xmm3
424424
; CHECK-NEXT: movsd %xmm3, (%rdi,%rdx,8)
425425
; CHECK-NEXT: movsd {{.*#+}} xmm3 = mem[0],zero
426426
; CHECK-NEXT: mulsd %xmm2, %xmm3
427-
; CHECK-NEXT: movsd %xmm3, 80(%rdi,%rcx,8)
428-
; CHECK-NEXT: addq $-16777216, %rax # imm = 0xFF000000
427+
; CHECK-NEXT: movsd %xmm3, 80(%rdi,%rax,8)
428+
; CHECK-NEXT: addq $-16777216, %rcx # imm = 0xFF000000
429429
; CHECK-NEXT: addq $-256, %rsi
430-
; CHECK-NEXT: decq %rcx
430+
; CHECK-NEXT: decq %rax
431431
; CHECK-NEXT: jne .LBB7_1
432432
; CHECK-NEXT: # %bb.2: # %return
433433
; CHECK-NEXT: retq

llvm/test/CodeGen/X86/reverse_branches.ll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,25 @@ define i32 @test_branches_order() uwtable ssp {
4848
; CHECK-NEXT: jg LBB0_7
4949
; CHECK-NEXT: ## %bb.2: ## %for.cond1.preheader
5050
; CHECK-NEXT: ## in Loop: Header=BB0_1 Depth=1
51-
; CHECK-NEXT: movl $-1, %r13d
52-
; CHECK-NEXT: movq %r15, %rbx
53-
; CHECK-NEXT: movq %r14, %rbp
51+
; CHECK-NEXT: movl $-1, %ebp
52+
; CHECK-NEXT: movq %r15, %rdi
53+
; CHECK-NEXT: movq %r14, %rbx
5454
; CHECK-NEXT: .p2align 4, 0x90
5555
; CHECK-NEXT: LBB0_3: ## %for.cond1
5656
; CHECK-NEXT: ## Parent Loop BB0_1 Depth=1
5757
; CHECK-NEXT: ## => This Inner Loop Header: Depth=2
58-
; CHECK-NEXT: incl %r13d
59-
; CHECK-NEXT: cmpl $999, %r13d ## imm = 0x3E7
58+
; CHECK-NEXT: incl %ebp
59+
; CHECK-NEXT: cmpl $999, %ebp ## imm = 0x3E7
6060
; CHECK-NEXT: jg LBB0_6
6161
; CHECK-NEXT: ## %bb.4: ## %for.body3
6262
; CHECK-NEXT: ## in Loop: Header=BB0_3 Depth=2
63-
; CHECK-NEXT: addq $1002, %rbp ## imm = 0x3EA
64-
; CHECK-NEXT: movq %rbx, %rdi
65-
; CHECK-NEXT: addq $1001, %rbx ## imm = 0x3E9
63+
; CHECK-NEXT: addq $1002, %rbx ## imm = 0x3EA
64+
; CHECK-NEXT: leaq 1001(%rdi), %r13
6665
; CHECK-NEXT: movl $1000, %edx ## imm = 0x3E8
6766
; CHECK-NEXT: movl $120, %esi
6867
; CHECK-NEXT: callq _memchr
69-
; CHECK-NEXT: cmpq %rax, %rbp
68+
; CHECK-NEXT: cmpq %rax, %rbx
69+
; CHECK-NEXT: movq %r13, %rdi
7070
; CHECK-NEXT: je LBB0_3
7171
; CHECK-NEXT: jmp LBB0_5
7272
; CHECK-NEXT: LBB0_7: ## %for.end11

llvm/test/CodeGen/X86/rotate-extract.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ define i32 @extract_add_1_comut(i32 %i) nounwind {
306306
define i32 @no_extract_add_1(i32 %i) nounwind {
307307
; X86-LABEL: no_extract_add_1:
308308
; X86: # %bb.0:
309-
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
310-
; X86-NEXT: leal (%ecx,%ecx), %eax
311-
; X86-NEXT: shrl $27, %ecx
309+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
310+
; X86-NEXT: leal (%eax,%eax), %ecx
311+
; X86-NEXT: shrl $27, %eax
312312
; X86-NEXT: orl %ecx, %eax
313313
; X86-NEXT: retl
314314
;

llvm/test/CodeGen/X86/twoaddr-lea.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ bb2:
6868
br label %bb6
6969

7070
bb3:
71-
; CHECK: subl %e[[REG0:[a-z0-9]+]],
72-
; CHECK: addq $4, %r[[REG0]]
71+
; CHECK: LBB3_3:
72+
; CHECK: addq $4, %r
73+
; CHECK: subl %e
7374
%tmp14 = phi i64 [ %tmp15, %bb5 ], [ 0, %bb1 ]
7475
%tmp15 = add nuw i64 %tmp14, 4
7576
%tmp16 = trunc i64 %tmp14 to i32

llvm/test/CodeGen/X86/twoaddr-pass-sink.ll

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)