[mlir-c] Fix testDialectMaterializeConstant review comments
Correct the misleading comment about the func dialect (it does have a
constant materializer; it just declines an i32 IntegerAttr), and assert
the documented insertion-point contract: the op lands in the current
insertion block and the rewriter's insertion point is preserved.
[AMDGPU] Exclude GFX11.7 from GFX11 VOPD interlock hazard fix (#225880)
Narrowed the scope of #220348 from all of GFX11. Also, this Hazard
is now defined as a feature in AMDGPU.td.
[CIR] Implement comdat 'name' for dtors (#225929)
Itanium emits the complete-object ctor/dtor as an alias to the base
object version when they are able to be put into COMDAT. However, this
is not currently implemented in CIR, where we are missing the 'comdat
with a name' functionality.
This patch limits that to ONLY FuncOp, and only does the named version
(instead of referencing its own name) for these ctor/dtors. Doing this
for the comdat attribute and for GlobalOp is left to a future patch.
This showed up in the 'root' project, where the wrong dtor was called as
a result!
Note: Claude helped me with the diagnosis, and wrote the reproducer.
[RISCV][P-ext] Add packed saturation intrinsics (#224432)
Add the Packed Saturation intrinsics `psati_i16x2`/`psati_i16x4`/
`psati_i32x2` and `pusati_u16x2`/`pusati_u16x4`/`pusati_u32x2`, their
codegen, and the Clang builtins and `riscv_packed_simd.h` wrappers.
See also
https://github.com/riscv/riscv-p-spec/blob/master/P-ext-intrinsics.adoc#packed-saturation
[MLIR][LLVM] Support inrange in GEP (#220424)
LLVM IR allows inrange(Start, End) on constant GEP expressions.
Import dropped it because getAsInstruction() does not preserve it.
Model it as LLVM_ConstantRangeAttr on GEPOp, reject empty ranges,
keep it through fold/SROA, and emit ConstantExpr::getGetElementPtr.
Fixes #128031
Assisted-by: gpt-5.6-sol
Assisted-by: grok-4.6
Signed-off-by: Letu Ren <fantasquex at gmail.com>
[CIR] Add cir.fshl and cir.fshr for elementwise funnel shifts (#222396)
Emit dedicated CIR ops from __builtin_elementwise_fshl/fshr instead of
cir.call_llvm_intrinsic.
Assisted-by: grok-4.6
Assisted-by: gpt-5.6-sol
Signed-off-by: Letu Ren <fantasquex at gmail.com>
[Mips] Restrict rdhwr+synci to Linux on MIPS R6 (#222566)
The rdhwr instruction reads synci_step, which is not allowed by OpenBSD
and is not available for ISA older than mips{32/64}r2.
Restrict the rdhwr+synci to Linux on MIPS R6 and fall back to
_flush_cache on all other MIPS targets including OpenBSD and pre-R6
Linux.
Fix #219896.
[mlir][Tensor] Reject empty expand_shape reassociation groups (#222648)
`tensor.expand_shape` with an empty reassociation group (e.g. `[[]]`)
used to abort the compiler: ExpandShapeOp::verify forwarded the group to
getSymbolLessAffineMaps, which asserts on missing affine expressions.
The sibling `tensor.collapse_shape` already rejects this input with a
clean diagnostic.
Extract the empty-group check into a helper shared by both tensor
reshape verifiers, invoke it from `ExpandShapeOp::verify`, and add an
invalid.mlir regression test that used to SIGABRT.
Fixes: #222602
[mlir] Add support for multi-parts diagnostics (#217804)
Under the current MLIR diagnostic infrastructure, emitting multiple
remarks at the same location requires calling the remark API multiple
times; moreover, every call to remark prints a note. This PR introduces
the concepts of "parts" To diagnostics. A streaming manipulator, called
`next`, similar to `std::endl` can be used to split multiple parts into
a single `InFlightDiagnostic`. This can be used for example to emit
multiple remarks at the same location, share the notes for those
remarks.
---------
Co-authored-by: Mehdi Amini <joker.eph at gmail.com>
[CFI] Don't create alias->alias chains. (#225951)
Discovered downstream after PR #225173, when CFI and HWASAN are
combined.
See also
https://github.com/llvm/llvm-project/pull/225173#issuecomment-5802301926
If there is an alias, we should leave it alone, find its aliasee, and
create a new external linkage alias to that. Even if local linkage, the
existing alias may be referenced by name by e.g. inline assembly.
[CIR] Don't create EH paths for lifetime-marker-only cleanups (#224829)
### summary
fix https://github.com/llvm/llvm-project/issues/224821
A lifetime marker is not a real cleanup, so it must never be the reason
an unwind edge exists.
Assisted by : Claude Opus5
[mlir] Fix canonicalizer crash when folding poison or kDynamic-sentinel index values (#223609)
Fixes two canonicalizer crashes, both in foldDynamicIndexList:
* #223333: tensor.extract_slice with a ub.poison offset/size crashes
canonicalization. ub.poison is matched as a constant but is not an
IntegerAttr, so getConstantIntValue returns nullopt and the subsequent
dereference asserts.
* #223336: a memref.subview offset/size/stride that wraps to
ShapedType::kDynamic (INT64_MIN) crashes canonicalization. Folding
INT64_MIN into the static array collides with the "dynamic" marker,
leaving dynamic-looking entries with no matching dynamic operands;
getMixedStrides() then asserts.
Only fold an operand when it is an integer constant whose value is not
ShapedType::kDynamic; poison and sentinel values stay dynamic operands.
Since foldDynamicIndexList is shared, this hardens all its callers.
Adds regression tests in mlir/test/Dialect/MemRef/canonicalize.mlir and
[2 lines not shown]
[CIR] Make sure ptr-cast-to-vbase is guarded. (#225969)
It isn't clear how we missed this, but classic codegen does checks this,
so we should too.
Claude Helped diagnose/debug, but I did the copy/pasting :D
[clang] Inconsistent attributes for `dllexport __cxxabiv1:: __fundamental_type_info` with `-fvisibility=hidden` (#215859)
Fixes #207963
The issue is `__declspec(dllexport)` and `hidden` visibility cannot be
used together. LLVM rejects `globals` that have both attributes.
For normal globals, `CodeGenModule::setGlobalVisibility` already handles
this by giving `dllexport` priority over the visibility implied by
`-fvisibility=hidden`. RTTI follows a different code path, though.
`ItaniumRTTIBuilder::BuildTypeInfo` applies the visibility and DLL
storage class separately to the generated `_ZTI*` and `_ZTS*` globals,
so the conflict was not resolved.
As a result, marking `__cxxabiv1::__fundamental_type_info` as
`dllexport` while compiling with `-fvisibility=hidden` could generate
RTTI globals with both hidden visibility and `dllexport`, causing LLVM
to fail verification with Broken module found. The same problem can
occur for `dllexport`-ed polymorphic classes when targeting Windows with
[7 lines not shown]
[BOLT] Include indirect calls/branches in basic block count estimation (#225104)
**Before:** When BOLT adjusts basic block counts in LBR mode it
considers outgoing branch counts when `--fix-block-counts` is enabled.
This adjustment was made according to the counts of direct calls and
branches which are recorded in the `Count` annotation made in
`DataReader::convertBranchData`. Indirect calls and branches are also
recorded within the `CallProfile` annotation, however they do not
contribute to the adjustment of basic block counts.
**After:** When making this adjustment to basic block counts, also
consider the counts of indirect calls and branches within the
`CallProfile` annotation. Do this by summing the execution counts of the
targets from this call/branch and considering them in determining the
maximum execution count of the basic block.
Assisted by: Codex. This was to write the tests for `x86` and `RISCV`
targets.
[mlir][Affine] Prevent buffer hoisting out of affine.parallel (#225324)
I noticed that `buffer-loop-hoisting` can move allocations out of
`affine.parallel`, making a buffer that should be local to each
iteration shared between the parallel iterations.
`AffineParallelOp` implements `LoopLikeOpInterface` but was missing the
`HasParallelRegion` trait, so `isSequentialLoop` treated it as
sequential. This adds the missing trait to `affine.parallel`, allowing
the pass to recognize the parallel boundary without changing the
hoisting logic.
I’ve added a regression test based on the reproducer in #225149, which
checks that the allocation stays inside `affine.parallel` and that the
store and load still use that allocation.
Fixes #225149.
[Clang][RISCV] Add packed widening subtraction accumulate intrinsics (#225764)
Add Clang header intrinsics for the RISC-V P-extension packed widening
subtraction accumulate operations:
- __riscv_pwsuba_i16x4
- __riscv_pwsuba_i32x2
- __riscv_pwsubau_u16x4
- __riscv_pwsubau_u32x2
Each computes rd + (a - b). The header wrappers use generic LLVM IR,
so RV32 selects the direct `pwsuba.*` / `pwsubau.*` instructions while
RV64 lowers the generic IR to the decomposition specified by the
P-extension intrinsic spec.
[Clang][RISCV] Add packed subvector insert intrinsics (#225771)
Add __riscv_pset_i8x4_i8x8, __riscv_pset_u8x4_u8x8,
__riscv_pset_i16x2_i16x4 and __riscv_pset_u16x2_u16x4, which insert a
32-bit packed subvector into a 64-bit packed vector. The index selects
the low or high half and must be a constant, enforced with
__enable_if__ as for the element insert intrinsics.
[flang][cuda] Defer data-transfer conversion in OpenACC routines (#225906)
Add an option so cuf-convert can leave cuf.data_transfer in the
host copy of an OpenACC routine until host/device specialization.
After that, transfers in a specialized device body become
assignments. Place allocas inside IsolatedFromAbove offload
regions so later FIR lowering does not store into a temporary
defined outside acc.compute_region.
[RISCV][P-ext] Select PPAIREO.W when packing with the high word of a value (#225763)
The low-half packed subvector insert is a v2i32 whose low word is the
subvector and whose high word is the high word of the wide vector,
which is exactly `ppaireo.w` (the low word comes from `rs1`, the high
word from `rs2`). Select it directly instead of `srli` + `pack`.
Adds `rvp-ppaireo-w.ll`; `rvp-simd-64.ll` is updated because the scalar
low insert in `test_insert_vector_32` now selects `ppaireo.w`.
[SCCP] Call correct simplifyBinOp in FP operation
This simplify FPOps with correct FMF, which covers non-inlined function
that can not be simplified by InstComb pass.
Also, update the TODO as we have cover that case in simplifyBinOp. But
per-element optimization is not enable as we don't have structure-like
LatticeMap for vector.
[AMDGPU] Fold a constant add/sub into the sudot4/sudot8 accumulator
Fold a constant add into the accumulator operand of sudot4 and sudot8 when
clamping is disabled:
```
sudot(a, b, C1, false) + C2 -> sudot(a, b, C1 + C2, false)
```
Subtraction by a constant is canonicalized to addition of its negation.
[AMDGPU][InstCombine] Fold zero dot operands to accumulator
Fold AMDGPU dot intrinsics when either operand is zero.
`dot(a, 0) = 0` and `dot(0, b) = 0`, so replace the intrinsic with its accumulator.
This avoids unrelated clamp and add/sub reassociation cases.
[AMDGPU][InstCombine] Canonicalize dot constant operands (#225083)
Move constant dot product source operands to the right hand side
and add tests for signed and unsigned dot intrinsics.
[flang] Fold fir.if with a constant condition (#225542)
Use `populateRegionBranchOpInterfaceInliningPattern` to fold `fir.if`
when the condition is a constant. It inlines the region the condition
selects, replacing uses of the `fir.if` results with the operands of
that region's `fir.result`, and erases the `fir.result`. A false
condition with no else region leaves nothing behind.