[llvm-c] Add function to print a `LLVMMetadataRef` directly (#238847)
I noticed that `LLVMMetadataRef`s cannot be printed directly via the C
API and must instead be done through `LLVMPrintValueAsString` and
`LLVMMetadataAsValue`, even though no such workaround is needed in C++.
This PR adds a `char *LLVMPrintMetadataToString(LLVMMetadataRef)`
function, similar to the other `LLVMPrint*ToString`s.
Those printing functions do not really have full tests, so I simply
tucked an assertion into `llvm-c-test --is-a-value-as-metadata`.
[clang][bytecode] Optimize `OffsetHelper` usage (#240908)
Do (most of) the checks outside of the helper. Most of the checks are
only possible on a subset of call sites.
[Support][LLD] Fast-path literal patterns in GlobPattern (#240639)
When `GlobPattern::create` parses a pattern with no glob metacharacters
or escape sequences, `SubGlobs` is empty and `PrefixSize` equals
`Pattern.size()`. Check `SubGlobs.empty()` at the start of
`GlobPattern::match` to compare `S == Pattern` directly instead of
calling `consume_front` and `consume_back`.
Also, in `lld::SingleStringMatcher`, add a check such that unquoted
literal section and file patterns in linker scripts use the existing
`ExactMatch` fast path.
Linking lld's own objects with the GNU ld default linker script (`ld
--verbose`), which contains various literal patterns before .text (from
@MaskRay):
```
wall (--threads=8) Assign sections instructions
main 237.6 ± 7.5 ms 149 ms 3.106e9
[3 lines not shown]
[llubi] Add support for vp.load and vp.store
These follow the semantics of llvm.masked.load/llvm.masked.store, just with a EVL-specific mask, so it reuses their code. The tests mostly follow the same format too.
The one extra-bit of immediate UB is that EVL > num vector elements is immediate UB, so that's handled explicitly.
[GVN] Allow loop-load PRE when the blocker is in an inner loop (#229580)
performLoopLoadPRE does not perform PRE when the blocker is inside an
inner loop. Allow it, and insert the reload in the exit block of the
inner loop that is directly nested in the loop being optimized, so the
reload runs at most once per iteration of that outer loop rather than
once per inner iteration.
PRE is not performed if the inner loop's exit edges do not all go to one
block, or if that block is not directly inside the loop being optimized
(for example, it exits into a sibling loop, where the reload could run
more often than the header load it replaces).
This is the follow-up to #228033, split from #227983 as suggested in
review. With #228033, `canBeFreed` no longer blocks the aliasing cases
this targets.
RFC: https://discourse.llvm.org/t/rfc-extending-gvns-loop-load-pre/91740
Assisted-by: Claude Opus 5
[LangRef] Make speculatable VP intrinsics with EVL > num elements non-UB (#240774)
For the remaining VP intrinsics which don't access memory:
- vp.merge
- vp.reduce.*
- vp.cttz.elts
- vp.splice
- vp.reverse
These are marked as speculatable. However the LangRef states that if the
EVL > the number of elements in the vector then the behaviour is
undefined. The two are inconsistent, so this PR tightens the result in
this scenario to be poison.
As a result the vp.reverse (and vp.splice) splitting needs to be updated
to clamp and freeze the EVL so it doesn't read outside of the stack
object.
[6 lines not shown]
[AArch64] Lower fixed-width masked gather/scatter using SVE (#240440)
This PR adds tests for the base cases of the masked gather/scatter
intrinsics. These operations are currently marked as illegal in the TTI
hooks isLegalMaskedGather/isLegalMaskedScatter, which means we scalarise
the intrinsics in IR before hitting SelectionDAG. The tests therefore
use the flag `-start-after codegenprepare` to avoid this so that we can
see how the intrinsics get lowered.
I've tried to add tests that take us down the widening, splitting and
promotion paths. I had to change the asserts in LowerMGATHER and
LowerMSCATTER so that we only require SVE to be available. I've also
commented out the half and bfloat element types, which currently get
stuck in an infinite legalisation loop. These will be handled in a
follow-on PR.
Once the codegen is solid and the cost model is representative of the
generated code I intend to mark all fixed-width gathers and scatters as
legal when SVE is available.
[clang] Cache default target feature attributes
Reuse the canonical default target-features attribute for functions
without per-function target settings. Keep target-specific overrides
separate from the default cache.
Three interleaved CTMark pairs reduce median compile time by 1.505%
and geomean by 1.950%.
Assisted-by: TRAE CLI (GPT-6)
Reviewers:
kito-cheng, nikic, AaronBallman, mshockwave, lukel97, asl, hubert-reinterpretcast, efriedma-quic
Pull Request: https://github.com/llvm/llvm-project/pull/240338
[clang][NFC] Don't track OpaqueValueExpr in bad conversion sequence (#238243)
Those OVE might be allocated on stack and we have already tracked their
types for diagnostics. So let's leave them null.
[OpenMP] Drop optimistic attributes from taskloop bound arguments
Under the default off -openmp-ir-builder-optimistic-attributes flag the
loop bounds get attributed as captures(none) nofree.
Changing them to AttributeSet() removes those claims from the
__kmpc_taskloop and __kmpc_taskloop_5 declarations. The runtime uses
the bounds' addresses to locate the bounds for each task it creates.
Even though the memory also reachtes the runtime through the task
argument the claims in the IR about the arguments are still wrong.