Skip to content

Commit

Permalink
[InlineSpiller] Don't call TargetInstrInfo::foldMemoryOperand with an…
Browse files Browse the repository at this point in the history
… empty list.

Since r287792 if we try to do that we will hit an assert.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289001 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Quentin Colombet committed Dec 8, 2016
1 parent 8302e1c commit aff0cae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/CodeGen/InlineSpiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,11 @@ foldMemoryOperand(ArrayRef<std::pair<MachineInstr*, unsigned> > Ops,
FoldOps.push_back(Idx);
}

// If we only have implicit uses, we won't be able to fold that.
// Moreover, TargetInstrInfo::foldMemoryOperand will assert if we try!
if (FoldOps.empty())
return false;

MachineInstrSpan MIS(MI);

MachineInstr *FoldMI =
Expand Down
22 changes: 22 additions & 0 deletions test/CodeGen/X86/implicit-use-spill.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# RUN: llc -run-pass=greedy -mtriple=x86_64-apple-macosx -o - %s 2>&1 | FileCheck %s

# Make sure we don't assert when we try to reload a value that is just implicitly used.
---
# CHECK: name: foo
# This test forces a spill of %0.
name: foo
registers:
- { id: 0, class: gr64 }
body: |
bb.0:
; CHECK: NOOP implicit-def [[VAL:%[0-9]+]]
; VAL should be spilled before csr_noregs, i.e., before we clobber all the registers
; CHECK-NEXT: MOV64mr [[SLOT:%stack.[0-9]+]], 1, _, 0, _, [[VAL]]
; CHECK-NEXT: NOOP csr_noregs
; We need to reload before the (implicit) use.
; CHECK-NEXT: [[RELOADED_VAL:%[0-9]+]] = MOV64rm [[SLOT]], 1, _, 0, _
; CHECK-NEXT: NOOP implicit [[RELOADED_VAL]]
NOOP implicit-def %0
NOOP csr_noregs
NOOP implicit %0
...

0 comments on commit aff0cae

Please sign in to comment.