[llvm] [RISCV] Ignore debug instructions in epilogue block checks (PR #219401)
Yongqiang Tian via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 28 03:31:47 PDT 2026
================
@@ -0,0 +1,76 @@
+; RUN: llc -mtriple=riscv32 -mattr=+save-restore -verify-machineinstrs < %s | FileCheck %s
+;
+; Debug instructions in the common return block should not affect save/restore
+; shrink wrapping.
+
+declare ptr @llvm.stacksave.p0()
+declare void @llvm.stackrestore.p0(ptr)
+declare void @notdead(ptr)
+
+define void @without_debug(i32 %n) nounwind {
+; CHECK-LABEL: without_debug:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: li a1, 32
+; CHECK-NEXT: bltu a1, a0, .LBB0_2
+; CHECK-NEXT: # %bb.1: # %if.then
+; CHECK-NEXT: call t0, __riscv_save_{{[0-9]+}}
+; CHECK: tail __riscv_restore_{{[0-9]+}}
+; CHECK: .LBB0_2: # %if.end
+; CHECK-NEXT: ret
+entry:
+ %cmp = icmp ult i32 %n, 33
+ br i1 %cmp, label %if.then, label %if.end
+
+if.then:
+ %size = zext i32 %n to i64
+ %stack = call ptr @llvm.stacksave.p0()
+ %buffer = alloca i8, i64 %size, align 16
+ call void @notdead(ptr %buffer)
+ call void @llvm.stackrestore.p0(ptr %stack)
+ br label %if.end
+
+if.end:
+ ret void
+}
+
+define void @with_debug(i32 %n) nounwind !dbg !4 {
+; CHECK-LABEL: with_debug:
+; CHECK: # %bb.0: # %entry
+; CHECK-NOT: __riscv_save
+; CHECK: li a1, 32
+; CHECK: bltu a1, a0, .LBB1_2
+; CHECK: # %bb.1: # %if.then
+; CHECK: call t0, __riscv_save_{{[0-9]+}}
+; CHECK: tail __riscv_restore_{{[0-9]+}}
+; CHECK: .LBB1_2: # %if.end
+; CHECK: ret
+entry:
+ %cmp = icmp ult i32 %n, 33
+ br i1 %cmp, label %if.then, label %if.end
+
+if.then:
+ %size = zext i32 %n to i64
+ %stack = call ptr @llvm.stacksave.p0()
+ %buffer = alloca i8, i64 %size, align 16
+ call void @notdead(ptr %buffer)
+ call void @llvm.stackrestore.p0(ptr %stack)
+ br label %if.end
+
+if.end:
+ #dbg_value(i32 0, !8, !DIExpression(), !9)
+ ret void, !dbg !10
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3}
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, emissionKind: FullDebug)
+!1 = !DIFile(filename: "x.c", directory: "/")
----------------
yqtian-se wrote:
Done. The directory field is required by the IR parser, so I simplified it to an empty string.
https://github.com/llvm/llvm-project/pull/219401
More information about the llvm-commits
mailing list