[llvm] [BOLT][RISCV] Precommit test for a conditional branch to end of the function (PR #218419)

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 24 07:06:15 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-risc-v

Author: Kito Cheng (kito-cheng)

<details>
<summary>Changes</summary>

A conditional branch whose target lies outside of the function is modeled as a
conditional tail call, and it tune it into a unconditional call
incorrectly.

We found this case during optimize clang with bolt.

---
Full diff: https://github.com/llvm/llvm-project/pull/218419.diff


1 Files Affected:

- (added) bolt/test/RISCV/cond-tail-call.s (+40) 


``````````diff
diff --git a/bolt/test/RISCV/cond-tail-call.s b/bolt/test/RISCV/cond-tail-call.s
new file mode 100644
index 0000000000000..7034617431b5f
--- /dev/null
+++ b/bolt/test/RISCV/cond-tail-call.s
@@ -0,0 +1,40 @@
+// RUN: %clang %cflags64 -o %t %s
+// RUN: llvm-bolt -o %t.bolt %t
+// RUN: llvm-objdump -d --disassemble-symbols=f %t.bolt | FileCheck %s
+
+  .text
+
+  .globl _start
+  .p2align 1
+_start:
+  call f
+  .size _start, .-_start
+  .globl f
+  .p2align 1
+// CHECK-LABEL: <f>:
+f:
+  /// An indirect branch BOLT cannot analyze, which makes the function
+  /// non-simple. This stands in for a jump table.
+// CHECK-NEXT: beqz a1,
+  beqz a1, .Lcont
+// CHECK-NEXT: jr a2
+  jr a2
+.Lcont:
+/// FIXME: the branch below is currently replaced by an unconditional tail call,
+/// which drops both the condition and the fall-through path.
+/// NOTE: This seems not reasonable in general, however this might created when
+///       program has __builtin_unreachable or undefined behavior.
+// CHECK-NEXT: j {{.*}} <g>
+  beqz a0, .Lend
+// CHECK-NEXT: li a0, 0x1
+  li a0, 1
+// CHECK-NEXT: ret
+  ret
+.Lend:
+  .size f, .-f
+
+  .globl g
+  .p2align 1
+g:
+  ret
+  .size g, .-g

``````````

</details>


https://github.com/llvm/llvm-project/pull/218419


More information about the llvm-commits mailing list