[llvm] [LLVM] List all instructions that are `!unpredictable` (PR #113502)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 23 15:56:44 PDT 2024


https://github.com/workingjubilee created https://github.com/llvm/llvm-project/pull/113502

Support for `select ... !unpredictable` was added some time ago and is even tested for some backends, but was apparently never documented. e.g. [llvm/test/CodeGen/X86/x86-cmov-converter.ll](https://github.com/llvm/llvm-project/blob/ac5a2010ad35a72de3e75a1883e2495345b92a73/llvm/test/CodeGen/X86/x86-cmov-converter.ll#L359-L430) tests to guarantee that `select ... !unpredictable` survives the infamous cmov-to-jmp conversion.

>From 198808ae87d196aeda577b8d3042741895014eda Mon Sep 17 00:00:00 2001
From: Jubilee Young <workingjubilee at gmail.com>
Date: Wed, 23 Oct 2024 15:48:03 -0700
Subject: [PATCH] [LLVM] List all instructions that are `!unpredictable`

Support for `select ... !unpredictable` was added some time ago and
is even tested for some backends, but was apparently never documented.
e.g. llvm/test/CodeGen/X86/x86-cmov-converter.ll tests to guarantee that
`select ... !unpredictable` survives the infamous cmov-to-jmp conversion.
---
 llvm/docs/LangRef.rst | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 6fa35486669d69..fc0129dec1c83d 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -7154,12 +7154,15 @@ sections that the user does not want removed after linking.
 '``unpredictable``' Metadata
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-``unpredictable`` metadata may be attached to any branch or switch
-instruction. It can be used to express the unpredictability of control
-flow. Similar to the llvm.expect intrinsic, it may be used to alter
-optimizations related to compare and branch instructions. The metadata
-is treated as a boolean value; if it exists, it signals that the branch
-or switch that it is attached to is completely unpredictable.
+``unpredictable``` can be used to express the unpredictability of control flow.
+Similar to the ``llvm.expect`` intrinsic, it may be used to alter optimizations
+related to compare and branch instructions. This is treated as a boolean value:
+Any instruction it is attached to signals it is completely unpredictable.
+
+``!unpredictable`` may be attached to, and will affect, these instructions:
+* branch
+* select
+* switch
 
 .. _md_dereferenceable:
 



More information about the llvm-commits mailing list