[analyzer][NFC] Check the lock state first in BlockInCriticalSectionChecker (#245798)
BlockInCriticalSectionChecker::isBlockingInCritSection is called for
every call. It matched the call against the list of blocking functions
before checking whether any critical section is active, which is rarely
the case and only needs a lookup of the ActiveCritSections trait. Check
the lock state first.
On some LLVM TUs (GVN, LiveVariables, RegionStore, SemaExpr) this
reduces the instructions of the static analyzer by 0.4-0.7%.
Assisted-by: Claude Opus 5.5
Co-authored-by: Gabor Horvath <gaborh at apple.com>
[SystemZ] Fix implicit defs of TRT and TRTR (#246033)
TRANSLATE AND TEST and TRANSLATE AND TEST REVERSE store the function
byte in GR2 and the argument address in GR1, and never modify GR0.
Replace the incorrect R0L implicit def with R2L.
Assisted by: IBM Bob
[SPIR-V] Fix getArg() assert on pointer constants in variadic call arguments (#214136)
`insertPtrCastOrAssignTypeInstr()` looks up the callee's formal
parameter for every pointer constant passed to a call, so a pointer
constant in a variadic position trips `getArg() out of range!`. OpenCL
`printf("%s", "a")` is enough to hit it. Skip operands that have no
formal parameter: like a parameter without a deduced element type, they
are left unchanged.
This PR was generated using AI
Co-authored-by: Marcos Maronas <mmaronas at amd.com>
[SPIRV] Lower llvm.minimumnum and llvm.maximumnum (#231759)
llvm.minimumnum and llvm.maximumnum aborted in the SPIR-V legalizer.
They are now expanded next to llvm.minimum/maximum into minnum/maxnum
(fmin/fmax), first replacing a NaN operand with the other operand and
then fixing the sign of zero, because fmin/fmax neither guarantee
signaling NaN handling nor order -0.0 below +0.0 as LangRef requires.
Split out of #218641.
This PR was generated using AI
[LinkerWrapper] Do not mistake ld64's -lto_library for -l<libname> (#216939)
On Darwin, clang passes ld64 `-lto_library <path>` and, for LTO links,
`-object_path_lto <path>`. The linker wrapper parsed these as the
`JoinedOrSeparate` options `-l` and `-o`, so the first failed with
`unable to find library -lto_library` and the second became the output
file `bject_path_lto`. This defines both as `Separate` options so they
are forwarded to the linker unchanged.
This PR was generated using AI
[LinkerWrapper] Use a four component triple for the host bundle entry (#216938)
The linker wrapper wrote the host entry of a HIP fat binary with the
default triple normalization, so a three component host triple such as
`x86_64-apple-macosx15.0.0` produced the entry
`host-x86_64-apple-macosx15.0.0`. clang-offload-bundler requires every
entry to be `<kind>-<arch>-<vendor>-<os>-<env>` and rejects that one, so
the HIP link fails. This normalizes the host entry with
`CanonicalForm::FOUR_IDENT`, as the driver already does for its own host
entry.
This PR was generated using AI
[AMDGPU] Do not always keep unclustered schedules under SGPR pressure (#244823)
UnclusteredHighRPStage keeps its schedule without checking the schedule
metric when the region has excess register pressure. With this patch,
that only happens when the schedule before or after has excess VGPR
pressure. SGPRs spills are cheap, and the unclustered schedule mostly
reduces VGPR pressure, so for regions with only excess SGPRs the
schedule metric now decides.
Before this change:
```
buffer_load v1, ...
s_wait_loadcnt 0x0
v_fma v2, v1... ; use load's result
buffer_load v, ... ; next load
s_wait_loadcnt 0x0
...
```
[13 lines not shown]
[CIR] Give the #cir.fenv parameters default values
The parameters of `#cir.fenv` were optional, and accessors substituted
a default for an absent one. The default floating-point environment
therefore had several spellings, such as `fenv<>`,
`fenv<except_mode = masked>` and the form CIRGen emits with all three
parameters, each a distinct attribute.
This makes the parameters default-valued: `tonearest`, `masked` and
`false`, the default floating-point environment. A parameter with its
default value is not printed, so each environment has one printed form
and `fenv<>` is the default one. A parameter spelled with its default
value still parses and gives the same attribute. An operation with
`fenv<>` is still constrained. Only an operation without the attribute
is not.
The default of `dynamic_rounding_mode` changes from `unknown` to
`tonearest`, in the documentation and in what the accessor returns for
an absent mode. Lowering already emitted `round.tonearest` for an
[9 lines not shown]
[CIR] Use one check for ignorable FP exceptions
Speculation and lowering each decided on their own whether a
constrained operation can ignore floating-point exceptions, and they
disagreed. An operation with `fenv<strict_except = false>` was
speculatable but lowered to `fpexcept.maytrap`, and one with masked but
strict exceptions was not speculatable but lowered to
`fpexcept.ignore`. `cir.vec.fcmp` never folded a constrained
comparison.
This adds `FenvAttr::canIgnoreExceptions()`, true when exceptions are
masked and not strict, and uses it in all three places:
- Speculation already used this condition and does not change.
- Lowering emits `fpexcept.ignore` when it holds, and otherwise
`fpexcept.strict` or `fpexcept.maytrap` by `strict_except`. Three
hand-written forms change: `fenv<strict_except = false>` goes from
maytrap to ignore, masked exceptions with `strict_except = true` from
ignore to strict, and unmasked or unknown exceptions without
[11 lines not shown]
[SystemZ] Use MSRKC/MSGRKC/MSC/MSGC for smul.with.overflow
On z14 and later (miscellaneous-instruction-extensions 2), lower
ISD::SMULO for i32 and i64 to the multiply-single instructions that
set the condition code. Overflow is reported as CC 3.
Add a SystemZISD::SMULO node and select it with MSRKC and MSGRKC for
register operands, and with MSC and MSGC for a memory operand. This
replaces the wide multiply plus compare of the high half (mgrk/srag/
cgrjlh for i64, lgfr/msgfr/srak/srlg/crjlh for i32) with a multiply
and a branch or select on CC.
Plain 'mul' selection is unchanged. Targets without the extension
keep the generic expansion.
Assisted by: IBM Bob
[CIR] Give complex FP add/sub the fenv memory effects (#242698)
`cir.complex.fadd` and `cir.complex.fsub` were `Pure` even with a
constrained `fenv` attribute, so they could be speculated or erased like
unconstrained ops. This derives them from `CIR_FenvOp`, as the other
fenv ops are: constrained ops read and write the FP environment and are
only conditionally speculatable, while unconstrained ops stay
effect-free. A new test covers both cases.
Assisted-by: Claude Code (Opus 5.5).
[LoadStoreVectorizer] Reset endpoint after chain break (#244610)
When an overlapping load starts a new chain, reset the tracked endpoint
to that load. Otherwise a later load can be incorrectly considered
contiguous with the previous chain and form an invalid chain.
[Mips] Keep constrained FP-to-int conversions on the chain (#245915)
lowerSTRICT_FP_TO_INT replaced STRICT_FP_TO_SINT and STRICT_FP_TO_UINT
with the non-strict nodes and passed the input chain through, so a
constrained conversion could be removed when its result was unused or
moved across calls that test or change the FP environment. The
non-strict FP_TO_UINT expansion also performs both conversions
unconditionally, which raises a spurious invalid exception for inputs
that are only in range for the unsigned conversion.
Lower STRICT_FP_TO_SINT to a chained MipsISD::STRICT_TruncIntFP that
selects to the same trunc instructions, and leave STRICT_FP_TO_UINT to
the generic strict expansion, which converts once.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[llvm-ir2vec] Emit compare predicates as triplets (#245752)
Embeddings use a vector for each compare predicate, but training could
not learn them because no triplet contained a predicate
[MIR2Vec] Map classless registers to a NoRegClass entry (#245956)
Generic vregs and physregs used to get a zero embedding and the first
virtual register class ID in triplets
[CIR] Keep complex and bool casts constrained in strict FP functions
In a strictfp function ClangIR emitted plain `fpext`, `fptrunc`,
`fptosi`, `sitofp`, `uitofp` and `fcmp une` for casts between complex
types and for conversions between floating-point values and bool, where
classic codegen emits constrained intrinsics. CIRGen created the
complex casts and `float_to_bool` without the `fenv` attribute,
LoweringPrepare dropped the attribute when it expanded a complex cast,
and the LLVM lowering of `float_to_bool` and `bool_to_float` ignored
it.
`createCast` now takes an optional `fenv` attribute. CIRGen passes the
current floating-point environment for `float_to_bool` and for the
complex cast kinds that convert floating-point values. The kinds that
only select or pack a part get none. LoweringPrepare passes the
attribute of a complex cast to the scalar casts of its expansion. With
`fenv`, `float_to_bool` lowers to the quiet constrained `fcmp` and
`bool_to_float` to the constrained `uitofp`.
[5 lines not shown]
[CIR] Use the FP environment of a compound assignment for its conversions
`ScalarExprEmitter::emitCompoundAssignLValue` emitted the conversions of
a compound assignment, from the left operand to the computation type
and back, without a `CIRGenFPOptionsRAII`. Under `#pragma STDC
FENV_ACCESS ON` the arithmetic was constrained but the conversions of
`x *= 0.1` or `i += x` got the default environment, and lowered to
plain `fpext`, `fptrunc`, `sitofp` and `fptosi` where classic codegen
emits constrained intrinsics.
Install the RAII with the features of the assignment after the left
operand is loaded, as classic codegen does.
Assisted-by: Claude Code (Opus 5.5).
[SystemZ] Fix implicit defs of TRT and TRTR
TRANSLATE AND TEST and TRANSLATE AND TEST REVERSE store the function
byte in GR2 and the argument address in GR1, and never modify GR0.
Replace the incorrect R0L implicit def with R2L.
Assisted by: IBM Bob
[lldb] Compare the concrete frame index for inlining (#240963)
`StackFrameList::GetFrameWithConcreteFrameIndex` compared each frame's
index with the concrete frame index it was given. The search starts at
the frame with that index, so the first comparison always matched, and
the function returned the frame at that index instead of the first frame
with that concrete frame index. The two differ when there are inlined or
artificial frames below the frame.
The function now compares each frame's concrete frame index. It skips
the artificial frames for a tail call, which have the concrete frame
index of the next unwound frame and come before it. A scripted frame can
be artificial too, but it has a concrete frame index of its own, so it
still matches.
A concrete frame index is the unwinder's, so
`Thread::GetFrameWithConcreteFrameIndex` now searches the unwinder's
frame list. With a scripted frame provider loaded, the thread's frame
list is the provider's, and that list numbers its frames differently.
[2 lines not shown]
[X86] Silence GCC -Wfree-nonheap-object false positive in LowerShift (#245993)
GCC 13+ warns that `~APInt` calls delete[] on "an unallocated object" in
the GFNI shift lambda. `SmallVector::push_back(T&&)` passes the address
of the temporary APInt to the out-of-line grow path, so GCC can no
longer prove its BitWidth is <= 64 and considers the `delete[] U.pVal`
path with the constant still stored in the union.
The APInts are 64 bits wide, so that path is never taken. Construct them
in place with emplace_back so there is no temporary to destroy.
---------
Co-authored-by: Claude <noreply at anthropic.com>
[AMDGPU] Remove R600 usage from llvm tests. NFC
Second step of removing the R600 (TeraScale) tests:
* [x] clang, flang, lld tests (#245524)
* [x] llvm tests (this patch)
Tests that only cover R600 are deleted, including the tests of the
`llvm.r600.*` intrinsics. In tests shared with GCN, the r600 RUN lines
and their now unused EG, CM and R600 checks and comments are removed,
and autogenerated checks are regenerated. The R600 cases in the yaml,
TableGen, TargetParser, Triple and DataLayout upgrade tests are removed
too:
```
; RUN: llc -mtriple=amdgcn -mcpu=tahiti < %s | FileCheck -check-prefixes=SI,FUNC %s
; RUN: llc -mtriple=r600 -mcpu=redwood < %s | FileCheck -check-prefixes=EG,FUNC %s
; EG: LDS_READ_RET
-->
[8 lines not shown]
[CIR] Give the #cir.fenv parameters default values
The parameters of `#cir.fenv` were optional, and accessors substituted
a default for an absent one. The default floating-point environment
therefore had several spellings, such as `fenv<>`,
`fenv<except_mode = masked>` and the form CIRGen emits with all three
parameters, each a distinct attribute.
This makes the parameters default-valued: `tonearest`, `masked` and
`false`, the default floating-point environment. A parameter with its
default value is not printed, so each environment has one printed form
and `fenv<>` is the default one. A parameter spelled with its default
value still parses and gives the same attribute. An operation with
`fenv<>` is still constrained. Only an operation without the attribute
is not.
The default of `dynamic_rounding_mode` changes from `unknown` to
`tonearest`, in the documentation and in what the accessor returns for
an absent mode. Lowering already emitted `round.tonearest` for an
[9 lines not shown]