-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[SPARC] Prevent meta instructions from being inserted into delay slots #161111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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`.
@llvm/pr-subscribers-backend-sparc Author: Koakuma (koachan) ChangesDo not move instructions with generic opcodes like This should fix crashes when compiling with, for example, Full diff: https://github.com/llvm/llvm-project/pull/161111.diff 2 Files Affected:
diff --git a/llvm/lib/Target/Sparc/DelaySlotFiller.cpp b/llvm/lib/Target/Sparc/DelaySlotFiller.cpp
index 6c19049a001cf..73d03fc271100 100644
--- a/llvm/lib/Target/Sparc/DelaySlotFiller.cpp
+++ b/llvm/lib/Target/Sparc/DelaySlotFiller.cpp
@@ -206,8 +206,8 @@ Filler::findDelayInstr(MachineBasicBlock &MBB,
if (!done)
--I;
- // skip debug instruction
- if (I->isDebugInstr())
+ // Skip debug and generic instructions.
+ if (I->isDebugInstr() || (I->getOpcode() <= TargetOpcode::GENERIC_OP_END))
continue;
if (I->hasUnmodeledSideEffects() || I->isInlineAsm() || I->isPosition() ||
diff --git a/llvm/test/CodeGen/SPARC/2011-01-19-DelaySlot.ll b/llvm/test/CodeGen/SPARC/2011-01-19-DelaySlot.ll
index 9ccd4f1c0ac9a..d4b21b248d60d 100644
--- a/llvm/test/CodeGen/SPARC/2011-01-19-DelaySlot.ll
+++ b/llvm/test/CodeGen/SPARC/2011-01-19-DelaySlot.ll
@@ -184,4 +184,30 @@ entry:
ret i32 %2
}
+define i32 @test_generic_inst(i32 %a) #0 {
+;CHECK-LABEL: test_generic_inst:
+;CHECK: ! fake_use: {{.*}}
+;CHECK: bne {{.*}}
+;CHECK-NEXT: nop
+
+%2 = call i32 @bar(i32 %a)
+ %3 = and i32 %2, 1
+ %4 = icmp eq i32 %3, 0
+ ; This shouldn't get reordered into a delay slot
+ call void (...) @llvm.fake.use(i32 %a)
+ br i1 %4, label %5, label %7
+5:
+ %6 = call i32 @bar(i32 %2)
+ br label %9
+
+7:
+ %8 = add nsw i32 %2, 1
+ br label %9
+
+9:
+ %10 = phi i32 [ %6, %5 ], [ %8, %7 ]
+ ret i32 %10
+}
+
+declare void @llvm.fake.use(...)
attributes #0 = { nounwind "disable-tail-calls"="true" }
|
;CHECK: bne {{.*}} | ||
;CHECK-NEXT: nop | ||
|
||
%2 = call i32 @bar(i32 %a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix indent and use named values in tests
// skip debug instruction | ||
if (I->isDebugInstr()) | ||
// Skip debug and generic instructions. | ||
if (I->isDebugInstr() || (I->getOpcode() <= TargetOpcode::GENERIC_OP_END)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generic is probably the wrong thing. isMetaInstruction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but I have a question:
Are debug instructions considered meta too? If so then I'll remove the redundant debug check too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but meta check is redundant with debug
llvm#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`.
llvm#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`. (cherry picked from commit 2e1fab9)
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
.