Skip to content

Commit 765b8b7

Browse files
committed
[𝘀𝗽𝗿] changes to main this commit is based on
Created using spr 1.3.4 [skip ci]
1 parent b2ea046 commit 765b8b7

File tree

6 files changed

+112
-1
lines changed

6 files changed

+112
-1
lines changed

llvm/docs/LangRef.rst

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27553,7 +27553,7 @@ in example below:
2755327553
.. code-block:: text
2755427554

2755527555
%cond = call i1 @llvm.experimental.widenable.condition()
27556-
br i1 %cond, label %solution_1, label %solution_2
27556+
br i1 %cond, label %fast_path, label %slow_path
2755727557

2755827558
label %fast_path:
2755927559
; Apply memory-consuming but fast solution for a task.
@@ -27639,6 +27639,54 @@ constant `true`. However it is always correct to replace
2763927639
it with any other `i1` value. Any pass can
2764027640
freely do it if it can benefit from non-default lowering.
2764127641

27642+
'``llvm.experimental.hot``' Intrinsic
27643+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27644+
27645+
Syntax:
27646+
"""""""
27647+
27648+
::
27649+
27650+
declare i1 @llvm.experimental.hot()
27651+
27652+
Overview:
27653+
"""""""""
27654+
27655+
This intrinsic returns true iff it's known that containing basic block is hot in
27656+
profile.
27657+
27658+
When used with profile based optimization allows to change program behaviour
27659+
deppending on the code hotness.
27660+
27661+
Arguments:
27662+
""""""""""
27663+
27664+
None.
27665+
27666+
Semantics:
27667+
""""""""""
27668+
27669+
The intrinsic ``@llvm.experimental.hot()`` returns either `true` or `false`,
27670+
deppending on profile used. Expresion is evaluated as `true` iff profile and
27671+
summary are availible and profile counter for the block reach hotness threshold.
27672+
For each evaluation of a call to this intrinsic, the program must be valid and
27673+
correct both if it returns `true` and if it returns `false`.
27674+
27675+
When used in a branch condition, it allows us to choose between
27676+
two alternative correct solutions for the same problem, like
27677+
in example below:
27678+
27679+
.. code-block:: text
27680+
27681+
%cond = call i1 @llvm.experimental.hot()
27682+
br i1 %cond, label %fast_path, label %slow_path
27683+
27684+
label %fast_path:
27685+
; Omit diagnostics.
27686+
27687+
label %slow_path:
27688+
; Additional diagnostics.
27689+
2764227690

2764327691
'``llvm.load.relative``' Intrinsic
2764427692
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,11 @@ def int_debugtrap : Intrinsic<[]>,
17221722
def int_ubsantrap : Intrinsic<[], [llvm_i8_ty],
17231723
[IntrNoReturn, IntrCold, ImmArg<ArgIndex<0>>]>;
17241724

1725+
// Return true if profile counter for containing block is hot.
1726+
def int_experimental_hot : Intrinsic<[llvm_i1_ty], [],
1727+
[IntrInaccessibleMemOnly, IntrWriteMem,
1728+
IntrWillReturn, NoUndef<RetIndex>]>;
1729+
17251730
// Support for dynamic deoptimization (or de-specialization)
17261731
def int_experimental_deoptimize : Intrinsic<[llvm_any_ty], [llvm_vararg_ty],
17271732
[Throws]>;

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7276,6 +7276,12 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
72767276
setValue(&I, getValue(I.getArgOperand(0)));
72777277
return;
72787278

7279+
case Intrinsic::experimental_hot:
7280+
// Default lowering to false. It's intended to be lowered as soon as profile
7281+
// is avalible to unblock other optimizations.
7282+
setValue(&I, DAG.getConstant(0, sdl, MVT::i1));
7283+
return;
7284+
72797285
case Intrinsic::ubsantrap:
72807286
case Intrinsic::debugtrap:
72817287
case Intrinsic::trap: {

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,6 +2827,14 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
28272827
}))
28282828
return nullptr;
28292829
break;
2830+
case Intrinsic::experimental_hot: {
2831+
// The intrinsic declaration includes sideeffects to avoid it moved. This
2832+
// prevents removing even if the intrinsic is unused. We should remove
2833+
// unused ones to enabled other optimizations.
2834+
if (CI.use_empty())
2835+
return eraseInstFromFunction(CI);
2836+
break;
2837+
}
28302838
case Intrinsic::assume: {
28312839
Value *IIOperand = II->getArgOperand(0);
28322840
SmallVector<OperandBundleDef, 4> OpBundles;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2+
; RUN: llc -o - %s | FileCheck %s
3+
4+
; REQUIRES: aarch64-registered-target
5+
6+
target triple = "aarch64-linux"
7+
8+
define i1 @test() {
9+
; CHECK-LABEL: test:
10+
; CHECK: // %bb.0: // %entry
11+
; CHECK-NEXT: mov w0, wzr
12+
; CHECK-NEXT: ret
13+
entry:
14+
%hot = call i1 @llvm.experimental.hot()
15+
ret i1 %hot
16+
}
17+
18+
declare i1 @llvm.expect.hot() nounwind
19+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3+
4+
define i1 @test() {
5+
; CHECK-LABEL: @test(
6+
; CHECK-NEXT: entry:
7+
; CHECK-NEXT: [[HOT:%.*]] = call i1 @llvm.experimental.hot()
8+
; CHECK-NEXT: ret i1 [[HOT]]
9+
;
10+
entry:
11+
%hot = call i1 @llvm.experimental.hot()
12+
ret i1 %hot
13+
}
14+
15+
define void @test_void() {
16+
; CHECK-LABEL: @test_void(
17+
; CHECK-NEXT: entry:
18+
; CHECK-NEXT: ret void
19+
;
20+
entry:
21+
%hot = call i1 @llvm.experimental.hot()
22+
ret void
23+
}
24+
25+
declare i1 @llvm.expect.hot() nounwind

0 commit comments

Comments
 (0)