Skip to content

Commit ed65875

Browse files
committed
Fix for PR34888.
The issue is that we assume operand zero of the input to the add instruction is a register. In this case, the input comes from inline assembly and operand zero is not a register thereby causing a crash. The code will bail anyway if the input instruction doesn't have the right opcode. So do that check first and let short-circuiting prevent the crash. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315285 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a59b5e1 commit ed65875

File tree

2 files changed

+125
-3
lines changed

2 files changed

+125
-3
lines changed

lib/Target/PowerPC/PPCMIPeephole.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,10 @@ bool PPCMIPeephole::simplifyCode(void) {
394394
for (unsigned i = 1; i < DefPhiMI->getNumOperands(); i += 2) {
395395
MachineInstr *LiMI =
396396
getVRegDefOrNull(&DefPhiMI->getOperand(i), MRI);
397-
if (!LiMI || !MRI->hasOneNonDBGUse(LiMI->getOperand(0).getReg()) ||
398-
!MDT->dominates(DefDomMI, LiMI) ||
399-
(LiMI->getOpcode() != PPC::LI && LiMI->getOpcode() != PPC::LI8))
397+
if (!LiMI ||
398+
(LiMI->getOpcode() != PPC::LI && LiMI->getOpcode() != PPC::LI8)
399+
|| !MRI->hasOneNonDBGUse(LiMI->getOperand(0).getReg()) ||
400+
!MDT->dominates(DefDomMI, LiMI))
400401
return false;
401402
}
402403

test/CodeGen/PowerPC/PR3488.ll

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
; RUN: llc < %s -mtriple=powerpc64le-unknown-unknown -verify-machineinstrs \
2+
; RUN: -mcpu=pwr8 | FileCheck %s
3+
module asm "\09.section \22___kcrctab+numa_node\22, \22a\22\09"
4+
module asm "\09.weak\09__crc_numa_node\09"
5+
module asm "\09.long\09__crc_numa_node\09"
6+
module asm "\09.previous\09\09\09\09\09"
7+
module asm "\09.section \22___kcrctab+_numa_mem_\22, \22a\22\09"
8+
module asm "\09.weak\09__crc__numa_mem_\09"
9+
module asm "\09.long\09__crc__numa_mem_\09"
10+
module asm "\09.previous\09\09\09\09\09"
11+
module asm "\09.section \22___kcrctab+node_states\22, \22a\22\09"
12+
module asm "\09.weak\09__crc_node_states\09"
13+
module asm "\09.long\09__crc_node_states\09"
14+
module asm "\09.previous\09\09\09\09\09"
15+
module asm "\09.section \22___kcrctab+totalram_pages\22, \22a\22\09"
16+
module asm "\09.weak\09__crc_totalram_pages\09"
17+
module asm "\09.long\09__crc_totalram_pages\09"
18+
module asm "\09.previous\09\09\09\09\09"
19+
module asm "\09.section \22___kcrctab+movable_zone\22, \22a\22\09"
20+
module asm "\09.weak\09__crc_movable_zone\09"
21+
module asm "\09.long\09__crc_movable_zone\09"
22+
module asm "\09.previous\09\09\09\09\09"
23+
module asm "\09.section \22___kcrctab+nr_node_ids\22, \22a\22\09"
24+
module asm "\09.weak\09__crc_nr_node_ids\09"
25+
module asm "\09.long\09__crc_nr_node_ids\09"
26+
module asm "\09.previous\09\09\09\09\09"
27+
module asm "\09.section \22___kcrctab+nr_online_nodes\22, \22a\22\09"
28+
module asm "\09.weak\09__crc_nr_online_nodes\09"
29+
module asm "\09.long\09__crc_nr_online_nodes\09"
30+
module asm "\09.previous\09\09\09\09\09"
31+
module asm "\09.section \22___kcrctab_gpl+split_page\22, \22a\22\09"
32+
module asm "\09.weak\09__crc_split_page\09"
33+
module asm "\09.long\09__crc_split_page\09"
34+
module asm "\09.previous\09\09\09\09\09"
35+
module asm "\09.section \22___kcrctab+__alloc_pages_nodemask\22, \22a\22\09"
36+
module asm "\09.weak\09__crc___alloc_pages_nodemask\09"
37+
module asm "\09.long\09__crc___alloc_pages_nodemask\09"
38+
module asm "\09.previous\09\09\09\09\09"
39+
module asm "\09.section \22___kcrctab+__get_free_pages\22, \22a\22\09"
40+
module asm "\09.weak\09__crc___get_free_pages\09"
41+
module asm "\09.long\09__crc___get_free_pages\09"
42+
module asm "\09.previous\09\09\09\09\09"
43+
module asm "\09.section \22___kcrctab+get_zeroed_page\22, \22a\22\09"
44+
module asm "\09.weak\09__crc_get_zeroed_page\09"
45+
module asm "\09.long\09__crc_get_zeroed_page\09"
46+
module asm "\09.previous\09\09\09\09\09"
47+
module asm "\09.section \22___kcrctab+__free_pages\22, \22a\22\09"
48+
module asm "\09.weak\09__crc___free_pages\09"
49+
module asm "\09.long\09__crc___free_pages\09"
50+
module asm "\09.previous\09\09\09\09\09"
51+
module asm "\09.section \22___kcrctab+free_pages\22, \22a\22\09"
52+
module asm "\09.weak\09__crc_free_pages\09"
53+
module asm "\09.long\09__crc_free_pages\09"
54+
module asm "\09.previous\09\09\09\09\09"
55+
module asm "\09.section \22___kcrctab+__page_frag_cache_drain\22, \22a\22\09"
56+
module asm "\09.weak\09__crc___page_frag_cache_drain\09"
57+
module asm "\09.long\09__crc___page_frag_cache_drain\09"
58+
module asm "\09.previous\09\09\09\09\09"
59+
module asm "\09.section \22___kcrctab+page_frag_alloc\22, \22a\22\09"
60+
module asm "\09.weak\09__crc_page_frag_alloc\09"
61+
module asm "\09.long\09__crc_page_frag_alloc\09"
62+
module asm "\09.previous\09\09\09\09\09"
63+
module asm "\09.section \22___kcrctab+page_frag_free\22, \22a\22\09"
64+
module asm "\09.weak\09__crc_page_frag_free\09"
65+
module asm "\09.long\09__crc_page_frag_free\09"
66+
module asm "\09.previous\09\09\09\09\09"
67+
module asm "\09.section \22___kcrctab+alloc_pages_exact\22, \22a\22\09"
68+
module asm "\09.weak\09__crc_alloc_pages_exact\09"
69+
module asm "\09.long\09__crc_alloc_pages_exact\09"
70+
module asm "\09.previous\09\09\09\09\09"
71+
module asm "\09.section \22___kcrctab+free_pages_exact\22, \22a\22\09"
72+
module asm "\09.weak\09__crc_free_pages_exact\09"
73+
module asm "\09.long\09__crc_free_pages_exact\09"
74+
module asm "\09.previous\09\09\09\09\09"
75+
module asm "\09.section \22___kcrctab_gpl+nr_free_buffer_pages\22, \22a\22\09"
76+
module asm "\09.weak\09__crc_nr_free_buffer_pages\09"
77+
module asm "\09.long\09__crc_nr_free_buffer_pages\09"
78+
module asm "\09.previous\09\09\09\09\09"
79+
module asm "\09.section \22___kcrctab_gpl+si_mem_available\22, \22a\22\09"
80+
module asm "\09.weak\09__crc_si_mem_available\09"
81+
module asm "\09.long\09__crc_si_mem_available\09"
82+
module asm "\09.previous\09\09\09\09\09"
83+
module asm "\09.section \22___kcrctab+si_meminfo\22, \22a\22\09"
84+
module asm "\09.weak\09__crc_si_meminfo\09"
85+
module asm "\09.long\09__crc_si_meminfo\09"
86+
module asm "\09.previous\09\09\09\09\09"
87+
module asm "\09.section \22___kcrctab+adjust_managed_page_count\22, \22a\22\09"
88+
module asm "\09.weak\09__crc_adjust_managed_page_count\09"
89+
module asm "\09.long\09__crc_adjust_managed_page_count\09"
90+
module asm "\09.previous\09\09\09\09\09"
91+
module asm "\09.section \22___kcrctab+free_reserved_area\22, \22a\22\09"
92+
module asm "\09.weak\09__crc_free_reserved_area\09"
93+
module asm "\09.long\09__crc_free_reserved_area\09"
94+
module asm "\09.previous\09\09\09\09\09"
95+
96+
@nr_cpu_ids = external local_unnamed_addr global i32, align 4
97+
98+
; Function Attrs: nounwind
99+
define void @__alloc_pages_nodemask() #0 {
100+
entry:
101+
%0 = call i64 asm sideeffect "ld${1:U}${1:X} $0,$1", "=r,*m"(i64* undef)
102+
br i1 undef, label %do.body.lr.ph.i.i.i, label %zone_page_state_snapshot.exit.i.i
103+
; CHECK: ld 3, 0(3)
104+
105+
do.body.lr.ph.i.i.i: ; preds = %entry
106+
br label %do.body.i.i.i
107+
108+
do.body.i.i.i: ; preds = %do.body.i.i.i, %do.body.lr.ph.i.i.i
109+
%x.022.i.i.i = phi i64 [ %0, %do.body.lr.ph.i.i.i ], [ %add7.i.i.i, %do.body.i.i.i ]
110+
%1 = load i8, i8* undef, align 1
111+
%conv.i.i458.i = sext i8 %1 to i64
112+
%add7.i.i.i = add i64 %x.022.i.i.i, %conv.i.i458.i
113+
%2 = load i32, i32* @nr_cpu_ids, align 4
114+
%cmp.i1.i.i = icmp ult i32 0, %2
115+
br i1 %cmp.i1.i.i, label %do.body.i.i.i, label %zone_page_state_snapshot.exit.i.i
116+
117+
zone_page_state_snapshot.exit.i.i: ; preds = %do.body.i.i.i, %entry
118+
%x.0.lcssa.i.i.i = phi i64 [ %0, %entry ], [ %add7.i.i.i, %do.body.i.i.i ]
119+
%3 = icmp sgt i64 %x.0.lcssa.i.i.i, 0
120+
unreachable
121+
}

0 commit comments

Comments
 (0)