[flang] Address review comments on chained concatenation fusion
Let concatenation fusion cross operations that only allocate, like the
hlfir.declare of a character literal operand, so that chains ending with a
literal are fused into one buffer. Only operations that may write or free
memory, or whose effects are unknown, now prevent the fusion.
Remove CharacterExprHelper::createConcatenate, which no longer has users.
Add bufferization tests for concatenations whose operands all have a
compile-time length, and for character kind 4.
[flang] Fuse chained character concatenations into one buffer
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.
[flang] Track character temporary lifetimes for safe stack placement
Dynamic character expression buffers could grow the stack on every
iteration of an unstructured loop because their lifetimes were hidden
from allocation placement. Emit hlfir.destroy for them, add an explicit
cleanup region to hlfir.yield_element, and preserve both through array
constructor lowering, elemental inlining, WHERE lowering and
bufferization, which now allocates these buffers with fir.allocmem.
When such an allocation cannot be hoisted out of the loop, reclaim its
stack space with one stacksave/stackrestore pair per block. Allocation
placement then keeps these temporaries on the stack in every mode,
including offload regions (except under -fdynamic-heap-array).
[flang] Address review comments on character temporary lifetimes
- stack-arrays: accept blocks with properly nested stacksave/stackrestore
pairs, such as the ones around calls with a runtime-length result, as
long as the allocations made inside a pair are freed before its end.
These allocations then reuse that pair.
Document that the block scope makes the peak stack the sum of the
promoted allocations.
- Only create a cleanup region from the current statement context scope,
so that array constructors do not get empty cleanup regions that block
elemental inlining.
- Always allocate kind conversion buffers on the heap and let allocation
placement move them to the stack, so that constant-length ones are
hoisted out of loops.
- Canonicalize away the hlfir.concat, hlfir.char_trim, hlfir.set_length
and hlfir.char_extremum results whose only uses are hlfir.destroy, such
as the SET_LENGTH bypassed by structure constructor lowering.
- Do not let hlfir.associate take over the storage of an hlfir.no_reassoc
operand that has other uses.
- Use %flang_fc1 in the new Fortran tests.
[clang-tidy] Make bugprone-argument-comment useful for C code (#237623)
systemd wants a /*name=*/ comment on every argument that is passed as a
bare
NULL, 0, true or false, and proposes a libclang script to check it
(https://github.com/systemd/systemd/pull/43725).
bugprone-argument-comment
can't do this for C code. It skips literals that come from a macro, and
C
spells NULL, and true and false before C23, with macros. It also skips
calls
in macro arguments such as assert_se(f(NULL)).
Let's add an IgnoreMacros option. When it's false, the check also adds
missing
comments to calls in macro arguments. CommentNullPtrs and
CommentBoolLiterals
now match the macros in the new NullPtrMacros and BoolLiteralMacros
options,
[18 lines not shown]
[mlir][ComplexToStandard] Preserve sign of zero im part in exp lowering (#242359)
The current logic sets `isYZero` to true when `y == +0` or `y == -0`,
and then sets the imaginary part to `+0`, discarding the initial sign.
This PR fixes this by instead setting the im part to y when `isYZero` is
true.
[AArch64][SystemZ] Don't crash on inline asm non-simple reg ops (#242225)
An aggregate operand whose size is not 1, 8, 16, 32, 64 or 128 bits has
ConstraintVT == MVT::Other. getRegForInlineAsmConstraint called
getSizeInBits() on it for the 'r' and 'x' constraints on AArch64 and the
'r', 'd', 'f' and 'v' constraints on SystemZ, hitting llvm_unreachable.
Return no register class for MVT::Other so the usual "cannot handle
indirect register inputs" / "could not allocate output register"
diagnostics are reported instead.
This is in line with already existing checks, e.g. on AArch64 for other
asm constraints (`w`).
Fixes #239086
Assisted-by: IBM Bob
[CGP] Drop support for non-gep address sinking (#242387)
We had two address sinking implementations, one using geps and the other
using ptrtoint + add + inttoptr. There was a TTI hook to control this,
but due to the way the check was performed, the gep mode was effectively
always enabled.
There is no good reason to ever use the non-gep sinking logic (which
does not preserve provenance information) and the code is effectively
dead right now, so delete it entirely.
[JumpTableToSwitch] Use ConstGlobalIterator to read jump table entries
Replace JTTS's own jump table parsing with the `ConstGlobalIterator` helper,
which is also used by instcombine's `foldCmpLoadFromIndexedGlobal`.
As a result JTTS now also handles GEPs without nusw/nuw flags, by masking the
index the same way instcombine does.
Note that the helper requires the indices to be in canonical index type, so
JTTS only works with canonical index types now. This is not a problem in
practice as JTTS only runs after instcombine.
[mlir][Vector] Reuse args buffers in WarpOpToScfIfPattern (#204311)
Args buffers are unused after lane 0 reads them inside the scf.if (the
Step 3 barrier fences other lanes), so reuse their storage for yielded
values via `memref.subview` when sizes are compatible. Reduces shared
memory footprint with no runtime overhead.
[RISCV] Add VeeR EH1 scheduling model and tuning (#240913)
VeeR EH1 is a 9-stage, 2-wide in-order core with two ALUs, one
load/store unit and one pipelined multiplier. Load and multiply results
reach an ALU consumer after 3 cycles, a branch can issue in the same
cycle as the load or multiply it depends on (it executes in the EX4
secondary ALU), and the divider stalls decode until it finishes. Checked
against cycle-accurate simulation of the v1.9 RTL.
Use the model for -mcpu=chipsalliance-veer-eh1, with tuning from the
same simulation: the RISC-V unroll preferences (TuneNoDefaultUnroll), no
load clustering (no data cache, one load/store unit), post-RA
scheduling, and a minimum jump-table size of 10 (a branch tree is
cheaper below that).
Assisted-by: Claude
[NVPTX] Only run ptxas on clz-popc-known-bits.ll if it supports sm_70 (#242961)
ptxas from CUDA 13 no longer supports sm_70, so the RUN line added in
#237793 fails on the NVPTX buildbots. Guard it the same way as other
sm_70 tests.
Assisted-by: Claude Code (Claude Opus 5.5)
[mlir] [arith] Combine op for select (#234818)
Fold select(c, F(a0, a1), F(b0, b1)) into F(select(c, a0, b0), select(c,
a1, b1))
Correctness provement:
Let's discuss the cases ignoring poison first.
As F is elementwise, we have
F(a1, a2, ..., a_n)[p] = F(a1[p], a2[p], ..., a_n[p])
then for
L = select(M, F(a0, a1, ..., a_n), F(b0, b1, ..., b_n))
R = F(select(M, a0, b0), select(M, a1, b1), ....)
for any position p, we have:
[35 lines not shown]
[clang-tidy] Add bugprone-macro-condition check (#210768)
Warns about inconsistent macro usage in preprocessor conditions.
#define USE_FOO 0
#ifdef USE_FOO
// ...no preprocessor directives testing the value of USE_FOO
#endif
Here USE_FOO is defined to a value (and furthermore defined to evaluate
to false) but the preprocessor condition only checks for the macro being
defined.
Fixes #27438
[orc-rt] Add SymbolLookupSet for interned symbol names (#242969)
SymbolLookupSet holds symbol names as StringPool::Ptrs, so building a
set doesn't copy the name strings. It has the same interface as
RemoteSymbolLookupSet, which holds plain std::strings.
sps::lookupInJITDylib now takes a SymbolLookupSet. To support this:
- StringPool::Ptr and WeakPtr can be serialized to SPSString, which
writes the string's value. Only serialization is supported:
deserializing into an interned string would need a StringPool, and SPS
deserialization has no way to obtain one.
- SymbolLookupSet can be serialized (but not deserialized) as an
SPSSymbolLookupSet. The wire format doesn't change, so controllers are
unaffected.
- SPSRemoteSymbolLookupSet.h is renamed to SPSSymbolLookupSet.h, after
the tag it defines. It now holds the traits for both kinds of set.
[libc][GPU] Enable scalbn/ldexp, rand, remainder for SPIR-V (#242212)
This PR is a follow up of
https://github.com/llvm/llvm-project/pull/236324 to fix more build
issues for SPIR-V compiler-rt builtin tests. "Undefined symbols" from
libc and libm still lead to a bunch of build failures such as rand,
srand, scalbn/f, remainder/f. Before the fix, building results:
Total Discovered Tests: 275
Unsupported: 125 (45.45%)
Passed : 128 (46.55%)
Failed : 22 (8.00%)
After the fix:
Total Discovered Tests: 275
Unsupported: 125 (45.45%)
Passed : 136 (49.45%)
Failed : 14 (5.09%)
8 more tests can build pass now.
[8 lines not shown]