[flang] Fuse chained character concatenations into one buffer (#239331)
Lowering creates one binary hlfir.concat per // operator, so `a // b //
c` was evaluated into an intermediate buffer that was then copied into
the result buffer. Add a canonicalization that folds a single-use
hlfir.concat into its user when no operation in between may modify or
release its operands, and bufferize hlfir.concat with any number of
operands. The buffer is now sized with the hlfir.concat length operand,
which can be computed outside of elemental loops, instead of the sum of
the operand lengths computed in the loop body.
I noticed this low hanging chained concat optimization when working on
the character expr refactor.
Note that we can still further optimize concat for the `a = b // c ...`
cases by using the lhs storage when there is no overlap (both for scalar
and arrays), I just did the easy change.
[mlir][llvm] Add DIEnumeratorAttr (#241969)
Add DIEnumeratorAttr to the LLVM dialect, modeling llvm::DIEnumerator.
This is the first step of supporting enumerations in the LLVM dialect
debug info, as discussed at
https://discourse.llvm.org/t/interest-in-adding-dienumerator-and-template-parameter-debug-info-to-the-llvm-dialect/92776.
Import and export follow in a separate patch.
The attribute has an optional name, the value as an IntegerAttr, and an
unsigned flag. LLVM stores the value as an APInt of any width and its
verifier does not restrict the width (there are existing tests with 128
bit enumerators), so an IntegerAttr keeps the exact width. The unsigned
flag is stored separately, as in LLVM. The assembly format is the
declarative struct format with no custom parsing or printing. Signless
integers print in their signed form, as usual in MLIR, so an unsigned
value such as 255 : i8 is accepted but printed as -1 : i8, and the flag
keeps the information:
```
[20 lines not shown]
[analyzer] Add an option to support unity-builds in CSA
Unity-build, a.k.a jumbo-build or unified-build is a practice to build
multiple C or C++ source files in a single compilation command by
including them into a synthetic TU main file using preprocessor
`#include` directives.
By default CSA would skip all functions in the files that are compiled
in this manner because the said functions would not be defined in the
"main TU" file, but in "headers", that are really #include'd sources.
Add unitybuild-file-extensions option (empty by default) that enables
CSA to start analysis of functions defined in #include'd files as long
as their extension matches one of the extensions configured.
Assisted by GPT-Sol LLM.
--
CPP-9564
[RISCV] Add fmv.h/w/d.x to foldMemoryOperandImpl for reloads. (#243192)
May help with #242978.
I found an old PR #78408 that also tried to do this, but it was more
complex and may have a bug for using an FSW to write a GPR stack
slot on RV64.
Assisted-by: Claude
[RISCV][P-ext] Fix assertion when legalizing i64 shift amounts on RV32 (#243366)
Previously, right shifts could incorrectly take the WSLL/WSLA path,
which also truncated the shift amount to i32. So the assertion failure
was never found.
After https://github.com/llvm/llvm-project/pull/242773, generic type
legalization can produce an i32 shift with an i64 shift amount on
RV32+P. Legalizing the shift amount then reaches an assertion that only
permits i32 shift amounts on RV64.
This commit allows the RV32+P case so generic legalization can expand
the shift amount.
Closes #243365
[MIR2Vec] Take register info from the function being embedded (#243113)
MIRVocabulary kept the register info of the first machine function, so
llvm-ir2vec looked up vregs of later functions in it and asserted or
picked the wrong register class
[RuntimeLibcalls] Model wchar_t arguments in libcall signatures
RuntimeLibcalls could describe int, size_t and several other C types
but had no way to describe wchar_t, so a libcall taking one could not
be declared with the correct parameter type and extension attribute.
The width of wchar_t is not a property of the triple alone: it can be
overridden by the wchar_size module flag, as -fshort-wchar does.
Add a WChar FuncArgType that converts to an integer of
Module::getWCharSize() bits, and derive its extension attribute in
RuntimeLibcallsInfo::getExtAttrForWCharParam.
Declare wmemset using the new type. A wchar_t as wide as int is
sign-extended wherever int is, so targets such as RISC-V, MIPS, PowerPC
and SystemZ now get signext on it, while AIX, z/OS and VE, where it is
unsigned, get zeroext.
Assisted-by: Claude
[RuntimeLibcalls] Add WCharSize field to RuntimeLibcallsInfo (NFC) (#241679)
`convertToIRType()` will need to know `wchar_t` size.
Make it available via private field of RuntimeLibcallsInfo.
Assisted-by: Claude
IR: Check for overlap before copying in AttributeSet::removeAttributes (#242957)
removeAttributes copied the whole set into an AttrBuilder to check if
the mask overlaps it, which it usually doesn't. Check the attributes
of directly with the mask and only build the AttrBuilder if something
needs to be removed.
callgrind instructions, opt -O3: kimwitu++ k.bc -0.16%, SPASS cnf.bc
-0.08%. CTMark instructions:u: ThinLTO -0.02% (kimwitu++ -0.06%)
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[mlir][memref] Promote buffers accessed via memref.copy (#232078)
This PR is a follow-up of #217793, which taught Mem2Reg to promote
buffers accessed through dynamic subviews and masked transfers.
This PR adds a `PromotableMemOpInterface` model for `memref.copy`. A
copy into the slot becomes a `vector.transfer_read` of the source, a
copy out becomes a `vector.transfer_write` to the target, and a copy
between two slots is rewritten one slot at a time so both buffers
disappear.
The transfers are built with
createReadOrMaskedRead/createWriteOrMaskedWrite. A copy from or to a
dynamically shaped memref now produces vector.mask {
vector.transfer_read/write }, and Mem2Reg promotes it through the
vector.mask model (#233705, #234251).
This PR also reorganizes the Mem2Reg tests. Since this logic spans the
MemRef and Vector dialects, there is no obvious dialect sub-directory
[14 lines not shown]
[scudo] Relax aligned_alloc restrictions. (#237352)
The standard for aligned_alloc relaxed the restriction on the size
parameter. Update the code to only disallow non-power of two alignments.
[llvm-ir2vec] Add -mtriple and codegen flags for MIR input (#242993)
MIR without an IR section was parsed for the host triple and -mcpu was
rejected since codegen flags became library options
[AMDGPU][NFC] Reduce simplifyAMDGCNMemoryIntrinsicDemanded arguments (#242200)
Follow-up to #240750, suggested in its review.
`simplifyAMDGCNMemoryIntrinsicDemanded` now takes only `IC`, `II` and
`DemandedElts`:
- it is a `GCNTTIImpl` member, like
`simplifyAMDGCNLaneIntrinsicDemanded`, so it reads the subtarget from
the class;
- `IsLoad` and the dmask operand index are derived from the intrinsic
(stores return void; image stores have the dmask after the stored
value).
No functional change.
Assisted-by: Claude Opus 5.5
Revert "[AMDGPU] Add implicit EXEC use to convergent inline asm (#242981)" (#243343)
This reverts commit daba4935fe66785f5452a3280c65925223b1c888.
This is not how this should be implemented
[AMDGPU] Ignore call clobbers in `fixShift64HiggRegBug` hazard check
The check for `fixShift64HighRegBug` checks the reg mask to find if
the next higher register is in use. This can give false positives.
Update it to only check for the actual registers which are used,
which is more conservative in some cases, but should help avoid miscompiles.
This bug was found due to a wrong result being computed in device libs with ASAN enabled.
[KnownFPClass][NFC] Move KnownFPClass::square out-of-line (#243342)
Moves `KnownFPClass::square` out-of-line. The only change is that
`applyOutputDenormalMode` is applied after `propagateNonNaN` and
`knownNot(fcNegative)`, but this change is unobservable.
[LoongArch] Legalize BUILD_VECTOR into a broadcast when all non-undef elements are identical (#169755)
When a BUILD_VECTOR consists of the same element (ignoring undefs),
it is better emitting a broadcast instead of multiple insertions.
Some cases which suffer performance regressions or have no benefits are
excluded in this commit.
[RuntimeLibcalls] Model wchar_t arguments in libcall signatures
RuntimeLibcalls could describe int, size_t and several other C types
but had no way to describe wchar_t, so a libcall taking one could not
be declared with the correct parameter type and extension attribute.
The width of wchar_t is not a property of the triple alone: it can be
overridden by the wchar_size module flag, as -fshort-wchar does.
Add a WChar FuncArgType that converts to an integer of
Module::getWCharSize() bits, and derive its extension attribute in
RuntimeLibcallsInfo::getExtAttrForWCharParam.
Declare wmemset using the new type. A wchar_t as wide as int is
sign-extended wherever int is, so targets such as RISC-V, MIPS, PowerPC
and SystemZ now get signext on it, while AIX, z/OS and VE, where it is
unsigned, get zeroext.
Assisted-by: Claude
[lld-macho] Keep branch-range extension thunks out of the symbol table
Make every branch-range extension thunk a local symbol. Until now,
thunks to external functions were added to the global symbol table as
private externs, and thunks to local functions had no symbol in the
output at all. This matches ld64 and ld-prime, which both emit every
branch island as a local symbol.
This also means that address assignment no longer adds anything to the
global symbol table, so code that reads it can run concurrently with
address assignment without any synchronization. A follow-up uses this to
prepare the export trie and the symbol table section while addresses are
being assigned.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
[lldb] Remove empty/corrupt DataFileCache symtab/dwarf-index (#242081)
The symtab and dwarf-index DataFileCache files have the full filepath
and arch of the file used in the filename, and then in the contents of
the file there is a CacheSignature. The CacheSignature is intended to
change when the file is rebuilt, so we can detect that a binary has been
rebuilt and remove the old cached results.
This CacheSignature is performed in ManualDWARFIndex::Decode and
Symtab::Decode,
```
bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr,
bool &uuid_mismatch);
```
This method sets `uuid_mismatch=true` when that has been detected. It
returns false when the file is empty or corrupt. The callers only
handled the first case,
[17 lines not shown]
[RuntimeLibcalls] Take the module in libcall signature converters (NFC)
The converters that turn declaration C type descriptions into IR types
and attributes take a context, a triple and a data layout. A libcall
declaration can also depend on properties recorded in the module itself
rather than in the triple, so pass the module instead and derive all
three from it.
Change getDefaultFunctionTy, getFunctionTy, getVariableType and the
static helpers they use to take a Module, and update the callers. No
functional change intended.
Assisted-by: Claude