Skip to content

Commit ab7b98f

Browse files
committed
[SPARC] Prevent generic opcodes from being inserted into delay slots
Do not move instructions with generic opcodes like `FAKE_USE`/`@llvm.fake.use` into delay slots, as they are not real machine instructions. This should fix crashes when running `clang -Og`.
1 parent 078e99e commit ab7b98f

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-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 debug and generic instructions.
210+
if (I->isDebugInstr() || (I->getOpcode() <= TargetOpcode::GENERIC_OP_END))
211211
continue;
212212

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

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

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

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

0 commit comments

Comments
 (0)