[X86] Compute `CTLZ` using fp math for `v4i32` on SSE2 targets (#190930)
This PR implements optimization for the `ISD::CTLZ` and
`ISD::CTLZ_ZERO_POISON` for X86 SSE2 target.
This PR builds upon #167034
Closes #161746
Co-authored-by: NishiB137 <cs23btech11041 at iith.ac.in>
Co-authored-by: VindhyaP312 <cs23btech11044 at iith.ac.in>
Co-authored-by: Simon Pilgrim <llvm-dev at redking.me.uk>
[SampleProfile] Recover hot contexts rejected by indirect-call promotion (#243628)
A sample profile can record samples for an indirect-call target under
its caller, as if the compiler had inlined the target. If the compiler
leaves the target out of line, those samples belong in the target's
standalone profile. Leaving them under the caller makes the standalone
function appear colder than it is.
This patch recovers those samples in both sample-profile inliners:
- Priority inliner: A target can be hot in absolute terms but account
for too few calls at a site to qualify for promotion. Previously, the
loader stopped at the first target that failed the percentage check. It
now records that target and continues through the remaining hot targets.
It stops when the targets are no longer hot. Several rejected targets at
the same call can therefore recover their samples.
- Iterative inliner (line-based AutoFDO): When the compiler promotes and
inlines one target, an indirect fallback remains for the other targets.
A later scan can mistake the already-inlined target for one that still
needs recovery. Tracking only one target per call can also miss other
[19 lines not shown]
[Passes] Declare -enable-profcheck-in-pipeline and -use-ctx-profile in TableGen (#249267)
Move them into IROptions and AnalysisOptions with exported getters.
CtxProfAnalysis reads -use-ctx-profile in run() instead of its
constructor.
Renames, with the old spellings kept as aliases:
```
-enable-profcheck-in-pipeline -> -profcheck-in-pipeline
```
Co-authored-by: Alexis Engelke <mail at aengelke.net>
[RISCV] Replace some uses of SplatFPOp with a ComplexPattern. NFC (#249166)
SplatFPOp is a PatFrag that checks 2 different opcodes. Every time it is
used we create 2 isel patterns. Since all those patterns handle multiple
element types and LMULs, this quickly adds up.
Replace it with a ComplexPattern like we do for integer. This reduces
the isel table size by 9.3%.
Assisted-by: Claude
[AArch64]Duplicate the repeated lower half of 128-bit build vectors
A 128-bit build vector whose upper half repeats the lower half, e.g.
(a, b, a, b), was lowered with one lane insert per element. Build the
lower half once and concatenate it with itself. Undef upper lanes match
anything; an all-undef upper half is left to the insert sequence, where
it needs no copy.
Assisted-by: Cursor
Pull-request: https://github.com/llvm/llvm-project/pull/247230
Reviewers: davemgreen, huntergr-arm, john-brawn-arm, paulwalker-arm, sdesmalen-arm
Reviewed-by: sdesmalen-arm
[mlir][OpenACC] Fix assertion macro expansion (#248975)
ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS expands to a comma-separated type
list. On systems where assert forwards its expression to another macro,
the commas are parsed as separate macro arguments.
Wrap the isa expression in an extra parenthesized group so it is passed
as one macro argument.
[DAG] Treat truncating an extend back to its source type as free (#249269)
I changed TargetLowering::isTruncateFree(SDValue, EVT) to treat
truncating a sign/zero/any extend back to its source type as free, since
the truncate just gives back the extend's operand. This is split out of
#236194 as requested there. That PR uses it to decide whether narrowing
uitofp vXi64 is worth it with AVX512DQ.
On its own, this lets the generic uitofp narrowing fold in DAGCombiner
handle `uitofp (zext <4 x i32> to <4 x i64>)`, which X86 used to
scalarize. The first commit adds a test for it with the current codegen.
It also lets the generic [su]itofp narrowing fold fire on other vector
extends. LoongArch and X86 both widen narrow vector sources in their own
[su]itofp combines, so the two folds kept undoing each other and
DAGCombiner hung (LoongArch lasx/ir-instruction/uitofp.ll, and X86
select-narrow-int-to-fp.ll with +avx512fp16). I fixed it by making both
targets reject the narrower type in isTypeDesirableForOp(SDNode *, EVT),
the same way SystemZ and AMDGPU already handle it.
[3 lines not shown]
[AArch64][GlobalISel] Add implicit defs for returned phyregs. (#248399)
This fixes a verifier error where physregs for a returned [2 x i64]
argument were not marked as defs on the call, leading them to being
undefined at point of use. As the argument in returned, the register may
be the origin reg used to set up the call, so only physregs need to be
added.
[InstSimplify] Fold vector infinity arms of ninf selects
Reuse m_Inf() for vector constants. When every defined lane of an arm
is an infinity, selecting it yields poison in that lane, so the other
arm is a valid replacement. Keep the select if any lane is finite.
AI assisted.
[Driver][AMDGPU] Search include/hipccl for hipstdpar/rocThrust headers (#246125)
Newer ROCm installs rocThrust under include/hipccl/thrust. Prefer it with --hipstdpar,
falling back to include/thrust.
AI assisted.
Co-authored-by: Yaxun (Sam) Liu <yaxun.liu at amd.com>
DAG: Use poison instead of undef in SimplifyDemandedVectorElts
I left getKnownUndefForVectorBinop since I'm not sure
if it's correct to just replace with poison.
[clangd] Show member names in structured binding inlay hints (#245943)
Show which member each structured binding refers to. For example,
`auto [.name=n: string, age: int] = person;`. The hint is omitted when
the binding has the same name as the member.
The hint is placed before the binding's name, consistent with the
existing
designator hints for aggregate initialization. It is controlled by the
existing `InlayHints.Designators` option.
Fixes clangd/clangd#2727
Assisted-by: Claude Code
Revert #247981 "[RISCV][MC] Diagnose symbol differences in instructions under relaxation" (#248804)
This reverts commit dc963db2bdd1166b5a6fb0fc0d95a6de1a86da4a.
The patch resolves `sym - .` in a PC-relative operand to `sym` by
comparing addresses, so identical lines assemble differently:
```
# llvm-mc -triple=riscv64 -mattr=+relax -filetype=obj a.s
nop
L:
beq a0, a1, X - L
beq a0, a1, X - L # error: unsupported symbol difference in instruction
nop
X:
ret
```
The diagnostic part will reland separately.
[AArch64] Update the Olympus scheduling model as per the SWOG changes (#248907)
The Olympus SWOG
https://docs.nvidia.com/olympus-cpu-core-software-optimization-guide-dp12531-001v0-7.pdf
has been updated for some AArch64 instructions, summarised below. We
update the Olympus scheduling model with updated schedules for the
following instruction groups.
| SWOG group | Old | New |
|---|---|---|
| Reduction (logical) | Lat 6 | Lat 5 |
| Reduction (add, B form) | Lat 11 | Lat 10 |
| Reduction (add, H form) | Lat 9 | Lat 8 |
| Reduction (add, S form) | Lat 8 | Lat 7 |
| Reduction (min/max, B form) | Lat 9 | Lat 8 |
| Reduction (min/max, H form) | Lat 8 | Lat 7 |
| Reduction (min/max, S form) | Lat 6 | Lat 5 |
| Reduction (D form) | Lat 5 (`UADDV` D: n/a, new) | Lat 4 |
| FP reduction (F16) | Lat 8 | Lat 12 |
[4 lines not shown]
MachineScheduler: Fix PressureDiffs assuming single physreg uses
updatePressureDiffs assumed each physreg has a single use and
overestimated the pressure when there were multiple. Also report a
physreg unit read and redefined by the same instruction as live in
RegPressureTracker::recede with lane masks. Drop the AMDGPU workaround
for this problem.
Assisted-by: Claude
[MIR] Round-trip the alignment of zero-size memory operands
Since #113028, the MIR printer omits the alignment of a zero-size memory
operand, e.g. of a WebAssembly reference type. However, the parser takes
`PowerOf2Ceil(0)` = 0 as the default alignment of such an operand, so it asserts
in `Align` when it reads the printed MIR back. The alignment itself is also
lost, e.g. the `align 4` of an externref global load.
This PR makes the parser use alignment 1 for a zero-size memory operand, and
makes the printer print any other alignment.
This PR was assisted by AI but I reviewed all the changes.
[ConstantFolding] Use the data layout null value for pointer casts
`ConstantFoldCastOperand` folds `inttoptr 0` to `null` and `ptrtoint null` to 0,
and it folds `ptrtoint (gep null, x)` to `x`. `SymbolicallyEvaluateGEP` folds
`gep null, x` to `inttoptr x`. All of these assume that the null pointer is
zero, which is going to be correct in the near future for an address space with
the `o` flag in the data layout. This PR folds the casts with the
DataLayout-aware `ConstantExpr` APIs, and folds the two GEP patterns only if the
base pointer has all bits zero, as discussed in #197544. Address spaces whose
null pointer is zero keep the same results, except that `inttoptr` of an integer
that truncates to zero now folds to `null`. LLParser, the bitcode reader, and
the pointer compare folds still assume that null is zero, which will be fixed in
later PRs.
This PR was assisted by AI but I reviewed all the changes.
[IR] Add data layout aware `getIntToPtr` and `getPtrToInt`
Without a data layout, `ConstantExpr::getIntToPtr` folds `inttoptr 0` to `null`,
and `ConstantExpr::getPtrToInt` folds `ptrtoint null` to 0. This is not correct
for an address space whose null pointer is all ones. This PR adds overloads of
`getIntToPtr`, `getPtrToInt`, `getPtrToAddr`, and `getCast` that take a `const
DataLayout &`, like the overload of `getGetElementPtr`. They use the null
pointer value of the address space: `null` and the bits of null convert to each
other, and zero converts to the zero pointer `inttoptr (i8 0 to ptr
addrspace(N))` if null is not zero. Nothing uses them yet though.
This PR was assisted by AI but I reviewed all the changes.
[NFC][InstSimplify] Add tests for pointer casts with an all-ones null pointer
The constant folds of `inttoptr`, `ptrtoint`, `ptrtoaddr`, and `getelementptr`
use the values of a zero null pointer, even in an address space whose null
pointer is all ones (the `o` flag in the DataLayout).
This PR was assisted by AI but I reviewed all the changes.
[X86] combineToExtendBoolVectorInReg - bail if the extension scale doesn't alias (#249251)
Don't attempt to fold if the broadcasted scalar can't be exactly aliased
across vector elements.
Fixes #249176
AMDGPU: Use round trip RUN lines for gfx7 disassembler tests
Replace the separate gfx7 disassembler tests with a %extract-encodings
RUN line in the existing assembler tests. The mimg test needs separate
assembler and disassembler checks, since the disassembler cannot
recover the vaddr width. Move the s_cbranch_join cases which do not
decode into their own assembler-only test.
Assisted-by: Claude