Skip to content

Commit 2e1fab9

Browse files
authored
[SPARC] Prevent meta instructions from being inserted into delay slots (#161111)
Do not move meta instructions like `FAKE_USE`/`@llvm.fake.use` into delay slots, as they don't correspond to real machine instructions. This should fix crashes when compiling with, for example, `clang -Og`.
1 parent 2ff635d commit 2e1fab9

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

llvm/lib/Target/Sparc/DelaySlotFiller.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ Filler::findDelayInstr(MachineBasicBlock &MBB,
206206
if (!done)
207207
--I;
208208

209-
// skip debug instruction
210-
if (I->isDebugInstr())
209+
// Skip meta instructions.
210+
if (I->isMetaInstruction())
211211
continue;
212212

213213
if (I->hasUnmodeledSideEffects() || I->isInlineAsm() || I->isPosition() ||

llvm/test/CodeGen/SPARC/2011-01-19-DelaySlot.ll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,29 @@ entry:
184184
ret i32 %2
185185
}
186186

187+
define i32 @test_generic_inst(i32 %arg) #0 {
188+
;CHECK-LABEL: test_generic_inst:
189+
;CHECK: ! fake_use: {{.*}}
190+
;CHECK: bne {{.*}}
191+
;CHECK-NEXT: nop
192+
%bar1 = call i32 @bar(i32 %arg)
193+
%even = and i32 %bar1, 1
194+
%cmp = icmp eq i32 %even, 0
195+
; This shouldn't get reordered into a delay slot
196+
call void (...) @llvm.fake.use(i32 %arg)
197+
br i1 %cmp, label %true, label %false
198+
true:
199+
%bar2 = call i32 @bar(i32 %bar1)
200+
br label %cont
201+
202+
false:
203+
%inc = add nsw i32 %bar1, 1
204+
br label %cont
205+
206+
cont:
207+
%ret = phi i32 [ %bar2, %true ], [ %inc, %false ]
208+
ret i32 %ret
209+
}
210+
211+
declare void @llvm.fake.use(...)
187212
attributes #0 = { nounwind "disable-tail-calls"="true" }

0 commit comments

Comments
 (0)