Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 9c15f4c

Browse files
committed
Fix for PR18396: Assertion: MO->isDead "Cannot fold physreg def".
InlineSpiller::foldMemoryOperand needs to handle undef call operands. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198679 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b4e0c9b commit 9c15f4c

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

lib/CodeGen/InlineSpiller.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,12 +1098,11 @@ foldMemoryOperand(ArrayRef<std::pair<MachineInstr*, unsigned> > Ops,
10981098
MRI.isReserved(Reg)) {
10991099
continue;
11001100
}
1101+
// Skip non-Defs, including undef uses and internal reads.
1102+
if (MO->isUse())
1103+
continue;
11011104
MIBundleOperands::PhysRegInfo RI =
11021105
MIBundleOperands(FoldMI).analyzePhysReg(Reg, &TRI);
1103-
if (MO->readsReg()) {
1104-
assert(RI.Reads && "Cannot fold physreg reader");
1105-
continue;
1106-
}
11071106
if (RI.Defines)
11081107
continue;
11091108
// FoldMI does not define this physreg. Remove the LI segment.

test/CodeGen/X86/fold-call-oper.ll

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck %s
2+
;
3+
; PR18396: Assertion: MO->isDead "Cannot fold physreg def".
4+
; InlineSpiller::foldMemoryOperand needs to handle undef call operands.
5+
6+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
7+
8+
@a = external global i32**, align 8
9+
@b = external global i32, align 4
10+
11+
; Check that the call targets are folded, and we don't crash!
12+
; CHECK-LABEL: foldCallOper:
13+
; CHECK: callq *{{.*}}(%rbp)
14+
; CHECK: callq *{{.*}}(%rbp)
15+
define void @foldCallOper(i32 (i32*, i32, i32**)* nocapture %p1) #0 {
16+
entry:
17+
%0 = load i32*** @a, align 8
18+
br label %for.body.i
19+
20+
for.body.i: ; preds = %for.body.i, %entry
21+
%exitcond5.i = icmp eq i32 undef, undef
22+
br i1 %exitcond5.i, label %for.body3.lr.ph.i, label %for.body.i
23+
24+
for.body3.lr.ph.i: ; preds = %for.body.i
25+
%call.i = tail call i32 %p1(i32* undef, i32 0, i32** null)
26+
%tobool.i = icmp eq i32 %call.i, 0
27+
br label %for.body3.i
28+
29+
for.body3.i: ; preds = %for.inc8.i, %for.body3.lr.ph.i
30+
%1 = phi i32* [ undef, %for.body3.lr.ph.i ], [ %.pre.i, %for.inc8.i ]
31+
%indvars.iv.i = phi i64 [ 1, %for.body3.lr.ph.i ], [ %phitmp.i, %for.inc8.i ]
32+
%call5.i = tail call i32 %p1(i32* %1, i32 0, i32** %0)
33+
br i1 %tobool.i, label %for.inc8.i, label %if.then.i
34+
35+
if.then.i: ; preds = %for.body3.i
36+
%2 = load i32* %1, align 4
37+
store i32 %2, i32* @b, align 4
38+
br label %for.inc8.i
39+
40+
for.inc8.i: ; preds = %if.then.i, %for.body3.i
41+
%lftr.wideiv.i = trunc i64 %indvars.iv.i to i32
42+
%arrayidx4.phi.trans.insert.i = getelementptr inbounds [0 x i32*]* undef, i64 0, i64 %indvars.iv.i
43+
%.pre.i = load i32** %arrayidx4.phi.trans.insert.i, align 8
44+
%phitmp.i = add i64 %indvars.iv.i, 1
45+
br label %for.body3.i
46+
}
47+
48+
attributes #0 = { noreturn uwtable "no-frame-pointer-elim"="true" }

0 commit comments

Comments
 (0)