[LV] Only charge legacy cost of forced scalars VPlan replicates. (#244725)
The legacy cost model charges forced scalars VF times their scalar cost,
even if VPlan folds them, hoists them or keeps them single-scalar. Only
pre-compute the legacy cost for forced scalars VPlan replicates per
lane; the VPlan cost model handles the rest.
This matches the existing behavior for InstsToScalarize.
Most test changes are due to no longer charging VF copies of `add %iv,
0` in the X86 interleave cost-model tests, which VPlan folds.
PR: https://github.com/llvm/llvm-project/pull/244725
[analyzer] Avoid printing names in CallDescription::matchNameOnly (#244863)
CallDescription::matchNameOnly printed the name of every constructor,
destructor and operator call into a string to compare it against each
CallDescription. Reject operator names unless the description starts
with "operator" and destructor names unless it starts with '~', and
compare constructor and destructor names to the record identifier, which
is what printing them yields for named records.
On some LLVM TUs (GVN, LiveVariables, RegionStore, SemaExpr) this
reduces the instructions of the static analyzer by 0.4-1.0% and the
cycles by 0.4-1.1%; peak memory is unchanged within noise. The
diagnostics are unchanged.
Assisted-by: Claude Opus 5.5
---------
Co-authored-by: Gabor Horvath <gaborh at apple.com>
[SCEV] Fold urem by multiples of vscale using vscale_range. (#245058)
vscale is a power of 2 that is at most the maximum from vscale_range, so
X urem (C * vscale) is 0 if X is a multiple of C * max(vscale).
This pattern is something that is useful when trying to reason about
remainders of trip counts in the loop vectorizer.
PR: https://github.com/llvm/llvm-project/pull/245058
[AMDGPU][NFC] Precommit tests for long-branch return-address clobbers (#244501)
Capture the current scratch reservation and scavenging behavior before
fixing the return-address clobber.
[OpenMP][OMPIRBuilder] Use the runtime CC for list<->global reduction helpers
#195911 gave the shuffle-and-reduce, inter-warp-copy and reduction
functions Config.getRuntimeCC(), which is spir_func on SPIR-V. The
list<->global helpers, which __kmpc_gpu_xteam_reduce_nowait calls through
the same kind of function pointer, kept the C calling convention, and so
did the two direct calls to them:
before after
define _omp_reduction_list_to_global_copy_func C RuntimeCC
define _omp_reduction_global_to_list_copy_func C RuntimeCC
define _omp_reduction_global_to_list_reduce_func C RuntimeCC
call list_to_global_copy (scratch copy-in) C RuntimeCC
call global_to_list_copy (scratch copy-back) C RuntimeCC
The device runtime calls the first three through ListGlobalFnTy pointers
(openmp/device/src/Reduction.cpp), i.e. with spir_func on SPIR-V.
RuntimeCC is C on all other targets, so their IR does not change.
emitListToGlobalReduceFunction() has no callers and is left as is.
[2 lines not shown]
[Attributor] Keep the calling convention when replacing an indirect call
When AAIndirectCallInfo knows the callee of an indirect call but cannot
promote the call (isLegalToPromote() fails), it creates a new direct call
with CallInst::Create(), which has the C calling convention:
define spir_func i32 @cb()
call spir_func void %fn() ; %fn = @cb
-passes=attributor call void @cb() (1)
-passes=attributor,instcombine store i1 true, ptr poison (2)
(1) does not match the callee's calling convention, so InstCombine
replaces it with (2). Copy the calling convention of the original call, as
promoteCall() keeps it when it changes the call in place.
On spirv64, OpenMPOpt runs the Attributor on the device runtime's
reduction code. Its spir_func calls of the shuffle-and-reduce and
inter-warp-copy callbacks cannot be promoted (a pointer argument's address
[6 lines not shown]
[SPIRV] Don't mark the barrier intrinsics nosync
The six llvm.spv.*memory.barrier* intrinsics are DefaultAttrsIntrinsics,
which makes them nosync. All six lower to OpMemoryBarrier or
OpControlBarrier with AcquireRelease semantics (selectBarrierInst() in
SPIRVInstructionSelector.cpp), so they do synchronize with other
invocations. amdgcn.s.barrier and the NVVM barriers are not nosync either.
Keep the other defaults and drop nosync:
declare void @llvm.spv.group.memory.barrier.with.group.sync()
before: convergent nocallback nofree nosync nounwind willreturn
after: convergent nocallback nofree nounwind willreturn
With nosync, OpenMPOpt deletes the workers' loop in a generic-mode OpenMP
kernel on spirv64-intel at -O3:
#pragma omp target teams distribute // generic mode
for (...) {
[14 lines not shown]
[ValueTracking] Add vector support to `computeKnownBitsFromEuclideanRem` (#241890)
Support vectors when inferring that Euclidean remainder expressions R +
(R < 0 ? A : 0) are non-negative, where R = srem X, Y and A is either Y
(when known non-negative) or abs(Y). Enables folding comparisons of the
result against zero. Respects demanded lanes when checking divisor
non-negativity.
Follow-up on #236900, which fixed #224449 for scalars.
[CIR] Add ABI vector kind tracking in cir::VectorType (#244303)
This adds a default-value field in cir::VectorType to track the ABI
vector kind. The default value is `Generic` meaning that the behavior
is, as it was before this change, not sub-type specific. This will be
needed during calling convention lowering for correct classification of
SVE types. The calling convention handling for SVE types will be added
in a later change.
Assisted-by: Cursor / claude-opus-5.5
[InstCombine] SimplifyDemandedVectorElts - add llvm.vector.shuffle handling (#245249)
Simplify the demanded elements of the mask operand using DemandedElts,
and use the mask's constant range to limit the demanded source elements.
This is the InstCombine equivalent of #244921.
Part of #244310
AI Note: I've used Claude Code to help me understand `InstCombine`
concepts and the codebase. The implementation and tests are my own.
[LangRef][llubi] Fix nsz handling for FP min/max intrinsics (#245117)
For FP min/max intrinsics and reductions, nsz only makes the order of
+0.0 and -0.0 non-deterministic and must not flip same-sign zeros. Clear
nsz before handleFMFFlags on inputs and handle opposite-sign zeros in
applyFPMinMax instead. Also clarify in LangRef that
llvm.vector.reduce.{fmaximum,fminimum} follow the same nsz semantics.
Fixes https://github.com/llvm/llvm-project/issues/233676
LLM used for test cases.
[AMDGPU] Don't unroll memcpy loops with sub-dword split accesses
If dword accesses aren't allowed at the copy's alignment, the unrolled
<64 x i32> loop is split into bytes, which causes heavy spilling. Only
unroll when dword accesses are allowed, and pick residual types the
alignment allows.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
[BOLT][AArch64] Enable clustered branch relaxation by default (#234932)
Use clustered relaxation by default when code relocations are available,
and keep --relax-exp as a hidden alias. Without relocations, fall back to
local branch relaxation or stub-insertion pass unless clustered relaxation
was explicitly requested, in which case exit with an error message.
Allow clustered relaxation to handle short-range branches without
requiring the --compact-code-model option.
Move tests that are exclusive to stub-insertion pass into a separate folder.
Link with test/Inputs/stub.c in eh-frame-hdr.test and eh-frame-overwrite.test
to avoid external-call thunks, whose FDEs would prevent the unwind sections
from being rewritten in place when using clustered relaxation.
[AMDGPU][Clang] Support the RF inline asm constraint (#244752)
Accept the AMDGPU-specific "RF" (flat memory address) inline asm
constraint in clang and lower it to "^RF" in IR. The backend support was
added in #241996. The "m" constraint needs no clang change since it is
handled by the generic TargetInfo code.
Add Sema tests for valid and invalid uses of "RF", and CodeGen tests
checking the IR constraint strings for "RF" and "m". Document "RF" in
the AMDGPU section of LangRef.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[AMDGPU] Test byte conversion through an i16 funnel shift
Keep both byte conversions and a store of the funnel-shift result to exercise the combine through both shift directions.
[AMDGPU] Look through any_extend in cvt_f32_ubyteN combine
Fold a shift through an any-extend when the selected byte is within the width of the shift result. This avoids an extra shift when converting elements of an unaligned vector load expanded into smaller pieces.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
[CIR] Dispatch va_arg lowering via target CIRABIRewriteContext subclasses (#244977)
#244116 included `clang/CIR/Dialect/Passes.h` from
`TargetLowering/CIRABIRewriteContext.h` for `cir::CallConvTarget`,
pulling
in the generated `Passes.h.inc` (`MLIRCIRPassIncGen`) from a
higher-level
library and breaking builds when `CIRABIRewriteContext.cpp` compiles
first.
Keep `CallConvTarget` out of `TargetLowering` by dispatching non-ignored
`cir.va_arg` lowering through a virtual `expandVAArg` hook on
`CIRABIRewriteContext`, implemented by X86_64 and AMDGPU subclasses
selected in `CallConvLoweringPass` (matching the structure of #244729).
Fixes build failure on
https://lab.llvm.org/buildbot/#/builders/sanitizer-windows.
Assisted-by: Gemini
[SystemZ] Select WCEFB/WCELFB/WCFEB/WCLFEB for vector-element conversions
On z15, use the scalar-in-vector convert instructions when one side of
an i32<->f32 conversion already lives in a vector register:
* (s|u)itofp of an extracted <4 x i32> element -> WCEFB/WCELFB, using
VREPF first for elements 1-3.
* fptosi/fptoui whose i32 result goes into element 0 of a vector
(scalar_to_vector, insert into undef, or splat) -> WCFEB/WCLFEB.
This avoids the GPR round trip (vlgvf + cefbr, cfebr + vlvgf). GPR<->FPR
conversions and variable-index extracts are unchanged.
Also fix the dest/source operand types of VCFEB/VCLFEB/WCFEB/WCLFEB
(which were reversed) and VCEFB/VCELFB (v128g -> v128f).
Add vec-conv-04.ll and vec-strict-conv-04.ll, including negative and
z14 checks.
[RISCV][GISel] Add G_ORC_B opcode and reuse SelectionDAG isel pattern. (#245331)
Eventually, we should also add computeKnownBits support to match SDAG.
Assisted-by: Claude
[SandboxVec][LoadStoreVec] Support mixed-type load vectorization (#236647)
- Allow reinterpretation of same sized values in load vectorization. A
chain of mixed types such as {i32, float} or {double, i32, i32} is
loaded as a vector of integers (as chosen by
`VecUtils::getWidenedType())`, each original load is unpacked from the
lanes it occupies, and then reinterpreted back to its own type with
`SameSizeReinterpret::reinterpretValue()`.
- Chains involving a non-integral pointer are left alone, since such a
pointer cannot be recovered from an integer lane.
Stacked on #243765.
Co-authored-by: Cursor <cursoragent at cursor.com>
---------
Co-authored-by: Cursor <cursoragent at cursor.com>
[NFC][VPlan] More tests for VPlan-based stride speculation
For #182595.
`@predicate_simplification_unknown_to_scev` has been added to #182595
quite some time ago and likely can be considered reviewed already.
Two other `@*might_trigger_ub_if_not_guarded` are for the latest review
round.
[GlobalOpt] Copy byval arguments when evaluating calls (#241675)
Fixes #241245.
The Evaluator bound the actual argument of a byval parameter directly to
the caller's object. The callee should get a private copy, so a later
store to the global changed the parameter. In the issue, GlobalOpt
evaluated the static constructor and committed a wrong value.
getFormalParams now copies the pointee of a byval argument byte by byte
into a temporary global and binds the parameter to it, the same way the
Evaluator models allocas. A byte-wise copy keeps the padding and does
not depend on the layout of the type. If a byte cannot be read, for
example when the object holds pointers, or the object is larger than 256
bytes, it gives up on the call as before.
The test is reduced from the issue and its checks are added with
update_test_checks.py. The lit tests under Transforms/GlobalOpt pass.
[NFC][VPlan] More tests for VPlan-based stride speculation
For #182595.
`@predicate_simplification_unknown_to_scev` has been added to #182595
quite some time ago and likely can be considered reviewed already.
Two other `@*might_trigger_ub_if_not_guarded` are for the latest review
round.
[AMDGPU] Read TTMP6 only if clusters are enabled (#244508)
The hardware only initializes TTMP6 when clusters are enabled, but
`llvm.amdgcn.cluster.workgroup.{id,max.id}.{x,y,z}` and
`llvm.amdgcn.cluster.workgroup.max.flat.id` read it without a check, so
they could potentially return stale values without clusters. The
programming model treats a launch without clusters as an implicit 1x1x1
cluster, so all of these values are 0.
Fixes LCOMPILER-3241.
This PR was assisted by AI but I reviewed all the changes.
[SampleProfile] Retrieve root profiles for inlined functions
Pre-link inlining can leave an inline frame whose samples are stored in a
separate root. Reading profiles only for surviving Function objects misses
that root. Looking only under the caller also fails when the profile and
IR inline trees disagree, including when an inner function is inlined first.
Put selective inline-root retrieval in the sample-profile reader so sample
loading and stale matching can both use it. Collect inline frames once,
prefer matching nested profiles, and batch missing-root reads by depth.
Do not let a missing outer profile hide a deeper frame or repeatedly request
names that are absent from the profile.
Let stale matching collect anchors inside eliminated inline frames and
reuse its existing matching algorithm and location-map distribution. For
MD5 profiles, resolve known callee hashes before the comparison loop.
Keep retrieval separate from permission to reuse sample counts. Post-link
fallback still checks the caller's count and probe checksum. Reject zero-head
[4 lines not shown]