Skip to content

Commit 842fcfb

Browse files
committed
merge main into amd-staging
2 parents 20ae949 + 13aff91 commit 842fcfb

38 files changed

+1698
-921
lines changed

clang/test/CodeGen/X86/avx512cd-builtins.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +avx512cd -emit-llvm -o - -Wall -Werror | FileCheck %s
33
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512cd -emit-llvm -o - -Wall -Werror | FileCheck %s
44
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +avx512cd -emit-llvm -o - -Wall -Werror | FileCheck %s
5+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512cd -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s
6+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +avx512cd -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s
7+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512cd -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s
8+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +avx512cd -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s
59

610

711
#include <immintrin.h>

clang/test/CodeGen/X86/avx512vlcd-builtins.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +avx512vl -target-feature +avx512cd -emit-llvm -o - -Wall -Werror | FileCheck %s
33
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512vl -target-feature +avx512cd -emit-llvm -o - -Wall -Werror | FileCheck %s
44
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +avx512vl -target-feature +avx512cd -emit-llvm -o - -Wall -Werror | FileCheck %s
5+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512vl -target-feature +avx512cd -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s
6+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +avx512vl -target-feature +avx512cd -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s
7+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512vl -target-feature +avx512cd -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s
8+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +avx512vl -target-feature +avx512cd -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s
59

610

711
#include <immintrin.h>

llvm/docs/BranchWeightMetadata.rst

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ Introduction
99
============
1010

1111
Branch Weight Metadata represents branch weights as its likeliness to be taken
12-
(see :doc:`BlockFrequencyTerminology`). Metadata is assigned to an
13-
``Instruction`` that is a terminator as a ``MDNode`` of the ``MD_prof`` kind.
14-
The first operator is always a ``MDString`` node with the string
15-
"branch_weights". Number of operators depends on the terminator type.
12+
(see :doc:`BlockFrequencyTerminology`). Metadata is assigned to a
13+
terminator ``Instruction`` as an ``MDNode`` of the ``MD_prof`` kind.
14+
The first operand is always an ``MDString`` node with the string
15+
"branch_weights". The number of operands depends on the terminator type.
1616

17-
Branch weights might be fetch from the profiling file, or generated based on
18-
`__builtin_expect`_ and `__builtin_expect_with_probability`_ instruction.
17+
Branch weights might be fetched from the profiling file or generated based on
18+
`__builtin_expect`_ and `__builtin_expect_with_probability`_ instructions.
1919

20-
All weights are represented as an unsigned 32-bit values, where higher value
21-
indicates greater chance to be taken.
20+
All weights are represented as unsigned 32-bit values, where a higher value
21+
indicates a greater chance of being taken.
2222

2323
Supported Instructions
2424
======================
2525

2626
``BranchInst``
2727
^^^^^^^^^^^^^^
2828

29-
Metadata is only assigned to the conditional branches. There are two extra
29+
Metadata is only assigned to conditional branches. There are two extra
3030
operands for the true and the false branch.
3131
We optionally track if the metadata was added by ``__builtin_expect`` or
3232
``__builtin_expect_with_probability`` with an optional field ``!"expected"``.
@@ -43,7 +43,7 @@ We optionally track if the metadata was added by ``__builtin_expect`` or
4343
``SwitchInst``
4444
^^^^^^^^^^^^^^
4545

46-
Branch weights are assigned to every case (including the ``default`` case which
46+
Branch weights are assigned to every case (including the ``default`` case, which
4747
is always case #0).
4848

4949
.. code-block:: none
@@ -74,7 +74,7 @@ Branch weights are assigned to every destination.
7474

7575
Calls may have branch weight metadata, containing the execution count of
7676
the call. It is currently used in SamplePGO mode only, to augment the
77-
block and entry counts which may not be accurate with sampling.
77+
block and entry counts, which may not be accurate with sampling.
7878

7979
.. code-block:: none
8080
@@ -89,9 +89,9 @@ block and entry counts which may not be accurate with sampling.
8989

9090
Invoke instruction may have branch weight metadata with one or two weights.
9191
The second weight is optional and corresponds to the unwind branch.
92-
If only one weight is set then it contains the execution count of the call
92+
If only one weight is set, then it contains the execution count of the call
9393
and used in SamplePGO mode only as described for the call instruction. If both
94-
weights are specified then the second weight contains count of unwind branch
94+
weights are specified then the second weight contains the count of unwind branch
9595
taken and the first weights contains the execution count of the call minus
9696
the count of unwind branch taken. Both weights specified are used to calculate
9797
BranchProbability as for BranchInst and for SamplePGO the sum of both weights
@@ -139,7 +139,7 @@ true, in other case condition is likely to be false. For example:
139139
^^^^^^^^^^^^^^^^^^^^
140140

141141
The ``exp`` parameter is the value. The ``c`` parameter is the expected
142-
value. If the expected value doesn't show on the cases list, the ``default``
142+
value. If the expected value doesn't appear in the cases list, the ``default``
143143
case is assumed to be likely taken.
144144

145145
.. code-block:: c++
@@ -159,15 +159,15 @@ Built-in ``expect.with.probability`` Instruction
159159
``__builtin_expect_with_probability(long exp, long c, double probability)`` has
160160
the same semantics as ``__builtin_expect``, but the caller provides the
161161
probability that ``exp == c``. The last argument ``probability`` must be
162-
constant floating-point expression and be in the range [0.0, 1.0] inclusive.
162+
a constant floating-point expression and be in the range [0.0, 1.0] inclusive.
163163
The usage is also similar as ``__builtin_expect``, for example:
164164

165165
``if`` statement
166166
^^^^^^^^^^^^^^^^
167167

168-
If the expect comparison value ``c`` is equal to 1(true), and probability
168+
If the expected comparison value ``c`` is equal to 1(true), and probability
169169
value ``probability`` is set to 0.8, that means the probability of condition
170-
to be true is 80% while that of false is 20%.
170+
being true is 80% while that of false is 20%.
171171

172172
.. code-block:: c++
173173

@@ -178,8 +178,8 @@ to be true is 80% while that of false is 20%.
178178
``switch`` statement
179179
^^^^^^^^^^^^^^^^^^^^
180180

181-
This is basically the same as ``switch`` statement in ``__builtin_expect``.
182-
The probability that ``exp`` is equal to the expect value is given in
181+
This is similar to the ``switch`` statement in ``__builtin_expect``.
182+
The probability that ``exp`` is equal to the expected value is given in
183183
the third argument ``probability``, while the probability of other value is
184184
the average of remaining probability(``1.0 - probability``). For example:
185185

@@ -195,8 +195,8 @@ the average of remaining probability(``1.0 - probability``). For example:
195195
CFG Modifications
196196
=================
197197

198-
Branch Weight Metatada is not proof against CFG changes. If terminator operands'
199-
are changed some action should be taken. In other case some misoptimizations may
198+
Branch Weight Metadata is not proof against CFG changes. If terminator operands'
199+
are changed, some action should be taken. Otherwise, misoptimizations may
200200
occur due to incorrect branch prediction information.
201201

202202
Function Entry Counts
@@ -212,7 +212,7 @@ invoked (in the case of instrumentation-based profiles). In the case of
212212
sampling-based profiles, this operand is an approximation of how many times
213213
the function was invoked.
214214

215-
For example, in the code below, the instrumentation for function foo()
215+
For example, in the code below, the instrumentation for function ``foo()``
216216
indicates that it was called 2,590 times at runtime.
217217

218218
.. code-block:: llvm
@@ -222,12 +222,12 @@ indicates that it was called 2,590 times at runtime.
222222
}
223223
!1 = !{!"function_entry_count", i64 2590}
224224
225-
If "function_entry_count" has more than 2 operands, the later operands are
225+
If "function_entry_count" has more than 2 operands, the subsequent operands are
226226
the GUID of the functions that needs to be imported by ThinLTO. This is only
227-
set by sampling based profile. It is needed because the sampling based profile
227+
set by sampling-based profile. It is needed because the sampling-based profile
228228
was collected on a binary that had already imported and inlined these functions,
229229
and we need to ensure the IR matches in the ThinLTO backends for profile
230230
annotation. The reason why we cannot annotate this on the callsite is that it
231-
can only goes down 1 level in the call chain. For the cases where
232-
foo_in_a_cc()->bar_in_b_cc()->baz_in_c_cc(), we will need to go down 2 levels
233-
in the call chain to import both bar_in_b_cc and baz_in_c_cc.
231+
can only go down 1 level in the call chain. For the cases where
232+
``foo_in_a_cc()->bar_in_b_cc()->baz_in_c_cc()``, we will need to go down 2 levels
233+
in the call chain to import both ``bar_in_b_cc`` and ``baz_in_c_cc``.

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,35 +2350,35 @@ class SelectionDAG {
23502350

23512351
/// If a SHL/SRA/SRL node \p V has a uniform shift amount
23522352
/// that is less than the element bit-width of the shift node, return it.
2353-
LLVM_ABI std::optional<uint64_t>
2353+
LLVM_ABI std::optional<unsigned>
23542354
getValidShiftAmount(SDValue V, const APInt &DemandedElts,
23552355
unsigned Depth = 0) const;
23562356

23572357
/// If a SHL/SRA/SRL node \p V has a uniform shift amount
23582358
/// that is less than the element bit-width of the shift node, return it.
2359-
LLVM_ABI std::optional<uint64_t>
2359+
LLVM_ABI std::optional<unsigned>
23602360
getValidShiftAmount(SDValue V, unsigned Depth = 0) const;
23612361

23622362
/// If a SHL/SRA/SRL node \p V has shift amounts that are all less than the
23632363
/// element bit-width of the shift node, return the minimum possible value.
2364-
LLVM_ABI std::optional<uint64_t>
2364+
LLVM_ABI std::optional<unsigned>
23652365
getValidMinimumShiftAmount(SDValue V, const APInt &DemandedElts,
23662366
unsigned Depth = 0) const;
23672367

23682368
/// If a SHL/SRA/SRL node \p V has shift amounts that are all less than the
23692369
/// element bit-width of the shift node, return the minimum possible value.
2370-
LLVM_ABI std::optional<uint64_t>
2370+
LLVM_ABI std::optional<unsigned>
23712371
getValidMinimumShiftAmount(SDValue V, unsigned Depth = 0) const;
23722372

23732373
/// If a SHL/SRA/SRL node \p V has shift amounts that are all less than the
23742374
/// element bit-width of the shift node, return the maximum possible value.
2375-
LLVM_ABI std::optional<uint64_t>
2375+
LLVM_ABI std::optional<unsigned>
23762376
getValidMaximumShiftAmount(SDValue V, const APInt &DemandedElts,
23772377
unsigned Depth = 0) const;
23782378

23792379
/// If a SHL/SRA/SRL node \p V has shift amounts that are all less than the
23802380
/// element bit-width of the shift node, return the maximum possible value.
2381-
LLVM_ABI std::optional<uint64_t>
2381+
LLVM_ABI std::optional<unsigned>
23822382
getValidMaximumShiftAmount(SDValue V, unsigned Depth = 0) const;
23832383

23842384
/// Match a binop + shuffle pyramid that represents a horizontal reduction

llvm/include/llvm/ProfileData/MemProfYAML.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ template <> struct MappingTraits<memprof::CallSiteInfo> {
217217
template <> struct MappingTraits<memprof::GUIDMemProfRecordPair> {
218218
static void mapping(IO &Io, memprof::GUIDMemProfRecordPair &Pair) {
219219
Io.mapRequired("GUID", Pair.GUID);
220-
Io.mapRequired("AllocSites", Pair.Record.AllocSites);
221-
Io.mapRequired("CallSites", Pair.Record.CallSites);
220+
Io.mapOptional("AllocSites", Pair.Record.AllocSites);
221+
Io.mapOptional("CallSites", Pair.Record.CallSites);
222222
}
223223
};
224224

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,7 +3299,7 @@ SelectionDAG::getValidShiftAmountRange(SDValue V, const APInt &DemandedElts,
32993299
return std::nullopt;
33003300
}
33013301

3302-
std::optional<uint64_t>
3302+
std::optional<unsigned>
33033303
SelectionDAG::getValidShiftAmount(SDValue V, const APInt &DemandedElts,
33043304
unsigned Depth) const {
33053305
assert((V.getOpcode() == ISD::SHL || V.getOpcode() == ISD::SRL ||
@@ -3312,7 +3312,7 @@ SelectionDAG::getValidShiftAmount(SDValue V, const APInt &DemandedElts,
33123312
return std::nullopt;
33133313
}
33143314

3315-
std::optional<uint64_t>
3315+
std::optional<unsigned>
33163316
SelectionDAG::getValidShiftAmount(SDValue V, unsigned Depth) const {
33173317
EVT VT = V.getValueType();
33183318
APInt DemandedElts = VT.isFixedLengthVector()
@@ -3321,7 +3321,7 @@ SelectionDAG::getValidShiftAmount(SDValue V, unsigned Depth) const {
33213321
return getValidShiftAmount(V, DemandedElts, Depth);
33223322
}
33233323

3324-
std::optional<uint64_t>
3324+
std::optional<unsigned>
33253325
SelectionDAG::getValidMinimumShiftAmount(SDValue V, const APInt &DemandedElts,
33263326
unsigned Depth) const {
33273327
assert((V.getOpcode() == ISD::SHL || V.getOpcode() == ISD::SRL ||
@@ -3333,7 +3333,7 @@ SelectionDAG::getValidMinimumShiftAmount(SDValue V, const APInt &DemandedElts,
33333333
return std::nullopt;
33343334
}
33353335

3336-
std::optional<uint64_t>
3336+
std::optional<unsigned>
33373337
SelectionDAG::getValidMinimumShiftAmount(SDValue V, unsigned Depth) const {
33383338
EVT VT = V.getValueType();
33393339
APInt DemandedElts = VT.isFixedLengthVector()
@@ -3342,7 +3342,7 @@ SelectionDAG::getValidMinimumShiftAmount(SDValue V, unsigned Depth) const {
33423342
return getValidMinimumShiftAmount(V, DemandedElts, Depth);
33433343
}
33443344

3345-
std::optional<uint64_t>
3345+
std::optional<unsigned>
33463346
SelectionDAG::getValidMaximumShiftAmount(SDValue V, const APInt &DemandedElts,
33473347
unsigned Depth) const {
33483348
assert((V.getOpcode() == ISD::SHL || V.getOpcode() == ISD::SRL ||
@@ -3354,7 +3354,7 @@ SelectionDAG::getValidMaximumShiftAmount(SDValue V, const APInt &DemandedElts,
33543354
return std::nullopt;
33553355
}
33563356

3357-
std::optional<uint64_t>
3357+
std::optional<unsigned>
33583358
SelectionDAG::getValidMaximumShiftAmount(SDValue V, unsigned Depth) const {
33593359
EVT VT = V.getValueType();
33603360
APInt DemandedElts = VT.isFixedLengthVector()
@@ -3828,7 +3828,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
38283828
Known = KnownBits::shl(Known, Known2, NUW, NSW, ShAmtNonZero);
38293829

38303830
// Minimum shift low bits are known zero.
3831-
if (std::optional<uint64_t> ShMinAmt =
3831+
if (std::optional<unsigned> ShMinAmt =
38323832
getValidMinimumShiftAmount(Op, DemandedElts, Depth + 1))
38333833
Known.Zero.setLowBits(*ShMinAmt);
38343834
break;
@@ -3840,7 +3840,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
38403840
Op->getFlags().hasExact());
38413841

38423842
// Minimum shift high bits are known zero.
3843-
if (std::optional<uint64_t> ShMinAmt =
3843+
if (std::optional<unsigned> ShMinAmt =
38443844
getValidMinimumShiftAmount(Op, DemandedElts, Depth + 1))
38453845
Known.Zero.setHighBits(*ShMinAmt);
38463846
break;
@@ -4887,15 +4887,15 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
48874887
case ISD::SRA:
48884888
Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
48894889
// SRA X, C -> adds C sign bits.
4890-
if (std::optional<uint64_t> ShAmt =
4890+
if (std::optional<unsigned> ShAmt =
48914891
getValidMinimumShiftAmount(Op, DemandedElts, Depth + 1))
4892-
Tmp = std::min<uint64_t>(Tmp + *ShAmt, VTBits);
4892+
Tmp = std::min(Tmp + *ShAmt, VTBits);
48934893
return Tmp;
48944894
case ISD::SHL:
48954895
if (std::optional<ConstantRange> ShAmtRange =
48964896
getValidShiftAmountRange(Op, DemandedElts, Depth + 1)) {
4897-
uint64_t MaxShAmt = ShAmtRange->getUnsignedMax().getZExtValue();
4898-
uint64_t MinShAmt = ShAmtRange->getUnsignedMin().getZExtValue();
4897+
unsigned MaxShAmt = ShAmtRange->getUnsignedMax().getZExtValue();
4898+
unsigned MinShAmt = ShAmtRange->getUnsignedMin().getZExtValue();
48994899
// Try to look through ZERO/SIGN/ANY_EXTEND. If all extended bits are
49004900
// shifted out, then we can compute the number of sign bits for the
49014901
// operand being extended. A future improvement could be to pass along the
@@ -4906,7 +4906,7 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
49064906
EVT ExtVT = Ext.getValueType();
49074907
SDValue Extendee = Ext.getOperand(0);
49084908
EVT ExtendeeVT = Extendee.getValueType();
4909-
uint64_t SizeDifference =
4909+
unsigned SizeDifference =
49104910
ExtVT.getScalarSizeInBits() - ExtendeeVT.getScalarSizeInBits();
49114911
if (SizeDifference <= MinShAmt) {
49124912
Tmp = SizeDifference +

0 commit comments

Comments
 (0)