[MLIR][LLVM] Preserve pointer-valued metadata operands on import (#215743)
convertMetadataToAttrImpl only modelled ConstantInt operands wrapped in
a ConstantAsMetadata, so any metadata node containing a pointer constant
could not be represented and the whole node was rejected.
Add #llvm.md_null and #llvm.md_addrspacecast to model
ConstantPointerNull and addrspacecast constant expressions, keeping the
address space so that `ptr null` and `ptr addrspace(1) null` stay
distinct. MDAddrSpaceCastAttr verifies that its operand is itself
pointer-valued metadata.
Global values are constants, so ValueAsMetadata::get wraps them in a
ConstantAsMetadata and they never reached the ValueAsMetadata case.
Match them in the ConstantAsMetadata case instead, which also
generalizes the existing function-only handling to any named global
value and makes the addrspacecast operand representable.
Mirror both attributes in ModuleTranslation::convertMetadataAttr so the
[6 lines not shown]
[InstCombine] Fold shl of constant by cttz into multiply of lowest set bit (#214517)
Currently, `C << cttz(X, true)` generates a DeBruijn lookup table on
RV64I (13 instructions).
And this patch adds a fold in InstCombine:
`C << cttz(X, true) --> (-X & X) * C`
This reduces the instruction count from 13 to 3 on RV64I.
The fold requires that cttz has a single use (to avoid increasing
instruction count)
Alive2 proof: https://alive2.llvm.org/ce/z/TmWxrT
clang/AMDGPU: Stop passing redundant -target-cpu to cc1
Now that the exact target is encoded in the triple's subarch field,
-target-cpu is redundant. This avoids polluting the resultant IR with
unwanted "target-cpu" attributes. The net result is the desired codegen
when compiling libraries for a major subarch and linking it into a
program compiled for a specific arch. e.g., compiling for "gfx9-generic"
would pollute the IR with "target-cpu"="gfx9-generic", so codegen
would ultimately be performed for the generic target even after
linking into the concrete gfx9 cpu. The specialization will now be
achieved by merging the triples without the linker or optimization
passes needing to fixup function attributes.
AMDGPU: Start using subarch in attributor instead of subtarget
Avoid querying the subtarget for functions when the relevant
properties are known from the triple. The various subtarget
group size functions should also be decoupled from the subtarget,
but those are trickier to untangle.
Co-authored-by: Claude (Opus 4.8) <noreply at anthropic.com>
clang: Start using new amdgpu subarch triples
Fixup invocations using --target=amdgcn + -mcpu to introduce
the subarch in the triple.
For offload toolchains, a single toolchain is constructed for the
top level amdgpu architecture, and the effective triple is used for
target specific tool invocations.
The specifics of the resource directory layout are tbd. This does
try to find resources in the subarch named directory. The paths
are searched at toolchain creation time, so that does not work
when there are multiple subarches.
Fixes #154925
[Clang] Support friend declarations with a dependent nested-name-specifier (#208345)
Fixes https://github.com/llvm/llvm-project/issues/104057
---
This patch adds support for friend declarations with a dependent NNS
AMDGPU: Start using subarch in attributor instead of subtarget
Avoid querying the subtarget for functions when the relevant
properties are known from the triple. The various subtarget
group size functions should also be decoupled from the subtarget,
but those are trickier to untangle.
Co-authored-by: Claude (Opus 4.8) <noreply at anthropic.com>
clang/AMDGPU: Stop passing redundant -target-cpu to cc1
Now that the exact target is encoded in the triple's subarch field,
-target-cpu is redundant. This avoids polluting the resultant IR with
unwanted "target-cpu" attributes. The net result is the desired codegen
when compiling libraries for a major subarch and linking it into a
program compiled for a specific arch. e.g., compiling for "gfx9-generic"
would pollute the IR with "target-cpu"="gfx9-generic", so codegen
would ultimately be performed for the generic target even after
linking into the concrete gfx9 cpu. The specialization will now be
achieved by merging the triples without the linker or optimization
passes needing to fixup function attributes.
clang: Start using new amdgpu subarch triples
Fixup invocations using --target=amdgcn + -mcpu to introduce
the subarch in the triple.
For offload toolchains, a single toolchain is constructed for the
top level amdgpu architecture, and the effective triple is used for
target specific tool invocations.
The specifics of the resource directory layout are tbd. This does
try to find resources in the subarch named directory. The paths
are searched at toolchain creation time, so that does not work
when there are multiple subarches.
Fixes #154925
AArch64: Use MIPatternMatch in PostLegalizerCombiner ext checks (#216512)
Replace the getVRegDef + opcode-check idiom with mi_match. Add an
m_GSExtInReg matcher for G_SEXT_INREG, which has an extra immediate
operand and so does not fit the plain unary-op matcher shape.
Co-authored-by: Claude (Opus 4.8) <noreply at anthropic.com>
X86: Fix optimizeCompareInstr crash on a compare from an undef register
getVRegDef returns null for undef sources, so the assert would fire.
Found by AI while working on other stuff.
Co-authored-by: Claude (Opus 4.8) <noreply at anthropic.com>
PeepholeOpt: Fix crash on copy from an undef register
Fix ValueTracker looking at the def chain of an undef subregister.
Found by AI while working on something else.
Co-authored-by: Claude (Opus 4.8) <noreply at anthropic.com>
[ASan] Register assert lit feature in `lit.cfg.py` (#216529)
Add this feature to test a functional change related to asserts, see
https://github.com/llvm/llvm-project/pull/213546#discussion_r3790705838.
And this will allow other people to add `// REQUIRES: asserts` in
testcases in the future too.
I follow the same pattern already used in `flang/test/lit.cfg.py` and
other configs.
[SSAF][UnsafeBufferAnalysis] Address follow up questions after the approval of #209354
- The analysis should not create entries for empty contributors, which otherwise is non-empty in the serialized format.
- use std IO instead of a tmp file for regex-ing FileCheck queries.
rdar://179151541 & rdar://179151882
[DebugInfo][NFC] Refactor debug record salvage (#215971)
Split address and variable-location salvage into helpers so the ordering
and the kill fallback stay visible in salvageDebugInfoForDbgValues, with the
variable-location helper returning whether it processed the record.
Rename the locals and parameters the move touches to say what they hold, and use
isAddressOfVariable() for the two #dbg_declare tests, which is the same
comparison.
Replace the address helper's single-use template with DbgVariableRecord
and pass it the instruction the caller already checked, rather than
recovering it with a dyn_cast the caller's check already covers.
Add a unit test for the dbg.assign address path.
No regressions on check-llvm or check-lldb; ran about 80 auto-generated C tests with 225ish locations and no differences in DW_AT_location on aarch64 at O2.
Assisted by AI.
[CIR][SYCL] Device kernel caller (#213771)
During device compilation, emit a SYCL kernel caller offload entry point
in
place of each function declared with the sycl_kernel_entry_point
attribute,
mirroring classic CodeGen's `CodeGenModule::EmitSYCLKernelCaller`.
Depends on #213728
[SSAF][UnsafeBufferAnalysis] Filter out type-constrained pointers from reachable unsafe pointers (#209354)
Integrate the TypeConstrainedPointers analysis results into
UnsafeBufferReachableAnalysis. The final result is filtered to exclude
type-constrained pointers.
The pointer flow graph is untouched. Removing type-constrained pointers
from the graph would introduce unsoundness.
Final step for rdar://179151541 and rdar://179151882
[APFloat][SelectionDAG] Support Float8E5M3FNU in convert.{to,from}.arbitrary.fp
Float8E5M3FNU was already accepted by the IR verifier, because
isValidArbitraryFPFormat is defined in terms of
getArbitraryFPFormatSizeInBits and that table covers it. It was missing
from getArbitraryFPSemantics, so SelectionDAGBuilder rejected
it with "not implemented format" and the verifier-clean IR failed to
compile. Add the mapping and the corresponding entries in the
expandCONVERT_{TO,FROM}_ARBITRARY_FP format allowlists.
Unlike every other format the expansions handle so far, Float8E5M3FNU is
unsigned: it has no sign bit, so all 8 bits go to a 5-bit exponent and a
3-bit significand.
Since an unsigned format cannot represent a negative value, a negative
input now saturates to zero when the saturate flag is set, and is poison
otherwise. -0.0 is excluded from that and still converts to +0, and the
check is ordered before the NaN case so a negative NaN still produces the
NaN encoding. APFloat treats constructing a negative value in an unsigned
[3 lines not shown]
[APFloat][NFC] Add unit test coverage for `getArbitraryFPSemantics` (#216501)
`isValidArbitraryFPFormat` and `getArbitraryFPFormatSizeInBits` have
unit tests, but `getArbitraryFPSemantics`, the mapping the conversion
intrinsics actually lower through, had none. Cover the formats it
supports, the valid formats it does not support yet, and invalid format
strings, and check that the two tables agree on the size of every format
with lowerable semantics.
Also add the missing Float8E5M3FNU case to the
`getArbitraryFPFormatSizeInBits` test.
[AArch64][GlobalISel] Do not create atomic truncstore (#216522)
After #213935 the i64->i32 truncstore was failing to create a COPY
correctly.
We do not have tablegen patterns, so mirror what SDAG does and do not
create
atomic truncstore.
[MIPS][NFC] test mips variadic aggregate handling (#216509)
mips64 has some bugs here that I'll address in a followup. The problem
is that we get `inreg {float}` items in the variable argument list. That
breaks for aggregates like `_Complex long double` or just `struct { long
double a; b }`.
[libc][bazel] Update bazel overlay for ceilf128 emulated float128 changes (#216515)
This updates the Bazel overlay following commit
e5174fe683e882f6bbd2ef023c9c9e293b273a98:
- Remove `:llvm_libc_types_float128` from `__support_math_ceilf128` deps
as `include/llvm-libc-types/float128.h` is no longer included.
- Add `:__support_cpp_bit` to `ceilf128` additional_deps for `bit_cast`.
- Add `ceilf128` math MPFR test target in
`libc/test/src/math/BUILD.bazel`.