[mlir][SPIR-V] Deserialize null array and struct constants (#231626)
Deserialize OpConstantNull for arrays and literal structs by recursively
building the ArrayAttr representation used by spirv.Constant. Preserve
rejection of unsupported constituent types and report the nested type
when a null value cannot be represented.
Allow OpConstantComposite with no constituents for empty structs so that
imported null empty structs can round-trip. Diagnose OpUndef
constituents explicitly instead of reporting them as missing normal
constants.
Document the supported representations and add binary deserialization,
round-trip, and negative tests for aggregate constants.
---------
Co-authored-by: Claude Fable 5.2 <noreply at anthropic.com>
AMDGPU: Fix double interval removal in SIOptimizeExecMaskingPreRA
An exec copy folded after its use was erased from an s_endpgm block
had its interval removed twice. Fixes an assert after 6a483810f0da.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[RISCV][P-ext] Use EVT in `combinePExtWidening*Acc` (#242687)
Fixes https://github.com/llvm/llvm-project/issues/242679.
The previous implementation assumes a simple value type, which is wrong
for weird-sized integers.
Assisted-by: Codex
DAG: Allow narrowing sint_to_fp source to the sext source type
Same as 241c94e3919e for uint_to_fp. The narrowing fold skipped
sint_to_fp (sext x) when the narrow type matched x, so sitofp (sext i32
to i64) was expanded as a 64-bit conversion on AMDGPU.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
AMDGPU: Add more sitofp of sext from i32 tests
These currently get the full i64 conversion expansion.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
CSKY: Use LastSubtargetCache in getSubtargetImpl
Migrate to the new common pattern for targets to cache the last
result.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
SystemZ: Use LastSubtargetCache in getSubtargetImpl
Migrate to the new common pattern and infrastructure.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
WebAssembly: Use LastSubtargetCache in getSubtargetImpl
Cache the last subtarget and use the new common pattern for targets.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
Mips: Use LastSubtargetCache in getSubtargetImpl
Migrate to use the new common infrastructure and pattern which caches
based on the last used subtarget.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
Bitstream: Move the slow path of Read out of line
SimpleBitstreamCursor::Read was too large to inline into its
callers. Separate out the slow error path.
CTMark instructions:u: ThinLTO -0.23% (kimwitu++ -0.72%)
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
AliasAnalysis: Use SmallVectors in AAResults
AAResults is rebuilt for each function whenever AAManager is invalidated,
and the default pipeline adds 3 or 4 AA results to it. With std::vector
each one regrows its storage on the second and third addition.
callgrind instructions, opt -O3: kimwitu++ k.bc -0.45%, SPASS cnf.bc
-0.12%, sqlite3 -0.03%. CTMark instructions:u: O3 -0.02%, ThinLTO -0.01%.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[ARM] Prevent debug values from causing extra Thumb1 spills (#237017)
Under Thumb1 execute-only code with an AAPCS frame chain, a debug value
for a stack-passed argument is represented with a fixed frame index.
canSpillOnFrameIndexAccess treats that debug-only operand as a real
access, so enabling debug info spills two additional callee-saved
registers.
Skip debug instructions in the scan. Keep a real stack-argument use
covered to ensure that frame-index elimination still reserves enough
registers.
Assisted-by: OpenAI Codex, co-reviewed by Claude and Yongqiang Tian.
[PowerPC] Model the CR defs of MTCRF used to restore callee-saved CRs
The epilogue restores the non-volatile CR fields (CR2-CR4) with a single
mtcrf. MTCRF takes only an FXM mask immediate and a GPR, and declares no
CR operands, so the post-RA scheduler sees no dependency between the
restore and instructions that read or write the restored CR bits. It can
therefore hoist the restore above those reads, making the function use the
caller's condition bits instead of its own.
Add the restored CR fields as implicit defs when building the MTCRF in
emitEpilogue() and restoreCRs(), matching the way the prologue already
adds implicit uses to MFCR. The scheduler now models the WAR/WAW
dependencies and keeps the restore after the last read.
This is a regression from #202339 (3fc6711ccaf6), which replaced multiple
MTOCRF instructions -- each with a CR field def -- with a single MTCRF.
Fixes #242250.
[LoongArch] Avoid left shift of negative immediates in foldLargeOffset() (#242761)
`ImmOp.getImm() << 12` is undefined when the LU12I.W immediate is
negative, e.g. `lu12i.w $a1, -524288` in `load_addr_offset_268435456`
(added by #242356), which UBSan reports on
sanitizer-aarch64-linux-bootstrap-ubsan.
RISCV: Migrate to LastSubtargetCache in getSubtargetImpl (#242559)
These already reused the last subtarget for functions with the same
function attribute set. Use LastSubtargetCache to additionally filter
to the subtarget relevant attributes and work towards all targets
using a common pattern.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[bazel][libc] Allow generated headers to be filtered by entrypoint
This PR splits the `libc_generated_header` into two steps. Instead of directly generating each header, we introduce a `libc_hdrgen_spec` rule that describes all the inputs to `hdrgen` for a given header, but does not produce a file.
Separately, we introduce a rule `libc_generated_headers` to actually create header files. Here, you can provide an `entrypoints` attribute to filter the produced header.
Note that this is not exactly equivalent to how the CMake build works. In this PR, LLVM-libc function objects are still compiled against unfiltered headers. CMake, whereas CMake produces filtered headers and compiles c++ sources against them.
If we want to be closer to CMake, we could instead make the entrypoint list configurable at the command-line. We could add a new provider `LibcEntrypointListInfo` and a companion `libc_entrypoint_list` rule that records all the entrypoint names we want to use when filtering headers. Then we would use a `label_flag` to select which `libc_entrypoint_list` should be used for filtering headers. I don't love this, since it's a global option and thus necessitates using transitions to create different header sets, but it is close to what CMake does.
[libc][mathvec] Cover the non-FMA expf rounding correction (#241112)
Add a targeted regression for 0xc16912cd and adjacent inputs, covering
broadcast and every mixed-lane position with the existing scalar
reference.
Assisted-by: GitHub Copilot
Signed-off-by: sriramshastry <sriramshastry at gmail.com>
[mlir][gpu] Let gpu::TargetOptions carry LLVM library options (#242734)
ModuleToObject creates the LLVMContext and TargetMachine for GPU
serialization without a cl::LibraryOptionsContext, so its TargetMachine
reads NVPTX, AMDGPU, CodeGen, and MC options from T::Global. Since
#242689, only LLVMParseCommandLineOptions still sets T::Global, and
#242692 removes that.
Add gpu::TargetOptions::setLibraryOptions. The NVVM, ROCDL, and XeVM
serializers pass the context to ModuleToObject, which assigns it to its
LLVMContext and points its TargetMachine at it.
LLM-aided
[clang] Preserve ext_vector_type locations during template substitution (#229328)
Instantiating a fixed-length `ext_vector_type` with a dependent element
type could emit an invalid-element diagnostic without a source location.
For example:
```cc
struct S {};
template <typename T> struct Vector {
typedef T type __attribute__((ext_vector_type(4)));
};
Vector<S> v;
```
Before:
[24 lines not shown]
[bazel][libc] Allow generated headers to be filtered by entrypoint
This PR splits the `libc_generated_header` into two steps. Instead of directly generating each header, we introduce a `libc_hdrgen_spec` rule that describes all the inputs to `hdrgen` for a given header, but does not produce a file.
Separately, we introduce a rule `libc_generated_headers` to actually create header files. Here, you can provide an `entrypoints` attribute to filter the produced header.
Note that this is not exactly equivalent to how the CMake build works. In this PR, LLVM-libc function objects are still compiled against unfiltered headers. CMake, whereas CMake produces filtered headers and compiles c++ sources against them.
If we want to be closer to CMake, we could instead make the entrypoint list configurable at the command-line. We could add a new provider `LibcEntrypointListInfo` and a companion `libc_entrypoint_list` rule that records all the entrypoint names we want to use when filtering headers. Then we would use a `label_flag` to select which `libc_entrypoint_list` should be used for filtering headers. I don't love this, since it's a global option and thus necessitates using transitions to create different header sets, but it is close to what CMake does.
[libc] Simplify getrandom syscall error handling (#242602)
Use syscall_checked<ssize_t> in the getrandom wrapper instead of
converting syscall errors by hand.
[Mips] Use a proper boolean for the select condition in lowerShift*Parts (#241685)
lowerShiftLeftParts and lowerShiftRightParts used (and Shamt, VT.bits)
directly as the condition of ISD::SELECT. That value is 0 or VT.bits
(32, or 64 for i128 on MIPS64), not 0/1. Since MIPS uses
ZeroOrOneBooleanContent, DAG combines may treat the condition as a 0/1
value, e.g. folding select(c, 0, 1) into xor c, 1, which miscompiles
when the condition is 32. For example 0x1FFFFFFFF >> (b & 32) returned
0x2100000001 instead of 1 for b = 32 on MIPS32.
Compare the masked shift amount against zero with setcc ne to form the
select condition. The DOUBLE_SELECT_I/DOUBLE_SELECT_I64 path used for
pre-MIPS4/MIPS32 in lowerShiftRightParts branches on the value being
non-zero, so it keeps using the masked shift amount directly.
Fixes #235261
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[GlobalISel] Ignore debug uses in direct single-use combines (#237643)
Debug uses can block the lshr/trunc and insert-vector chain combines in
`CombinerHelper`, making ordinary Machine IR depend on debug
information.
This patch counts only non-debug uses and uses a non-debug iterator when
retrieving the insert-vector user. The regression tests cover both
combines and fail without the change.
These direct `MRI.hasOneUse()` checks are not covered by #237070, which
changes the `m_OneUse` matcher.
This issue was found through a source audit. AI assisted with the
analysis and development of the fix.