[InstCombine] Allow multi-use icmp in (add (..) (sext (icmp ne A, 0))) fold. (#243186)
The fold to umax(A, 1) is profitable even if the icmp has other users:
it replaces the two adds and the sext with a single umax and the icmp
stays alive for its other users.
This shows up after LoopVectorize, where the trip count
(A + 1 - umin(A, 1)) shares umin(A, 1) with the runtime check bounds.
Triggers in ClamAV and also SPEC2017:
https://github.com/dtcxzyw/llvm-opt-benchmark-nightly/pull/2051
PR: https://github.com/llvm/llvm-project/pull/243186
[ConstraintElim] Split signed min/max across their operands when checking a compare
The existing constraint systems only record the bounds that hold for both
operands of a min/max (smax(a, b) >= a and >= b, smin(a, b) <= a and <= b). The
other direction is a disjunction, which cannot be recorded as a fact. When a
compare of signed decompositions involves a min/max result, split it into its
operands: the decomposition is monotonic in that result, so it is the max or min
of its values on each side, and the relation holds for all or for either side
respectively.
https://alive2.llvm.org/ce/z/zsGkJ-
[libc][math] Add multiply_sub, add_multiply, and sub_multiply to multiply_add.h.
- Add fputil::multiply_sub (x * y - z), fputil::add_multiply (x + y * z), and
fputil::sub_multiply (x - y * z) alongside fputil::multiply_add (x * y + z).
- Use template-based hardware FMA dispatch and size-aware inline overloads so
explicit multiply_add<T> calls also use hardware FMA when available.
- Add NumberPair<T> add/sub overloads in double_double.h, and matching
multiply_sub, add_multiply, and sub_multiply overloads for DoubleDouble and
DyadicFloat.
- Add unit tests in libc/test/src/__support/FPUtil/multiply_add_test.cpp.
[NVPTX] Don't crash on image handles that are not params or globals (#238504)
NVPTXReplaceImageHandles hits llvm_unreachable when a texture, sampler
or surface handle is defined by anything other than a param load,
texsurf_handles or a copy, e.g. a handle returned by a call, merged by a
phi or computed with arithmetic. Release builds go on to crash in the
AsmPrinter.
Such handles have no symbol to replace them with, so leave them in a
register, as is already done for CUDA param loads. This needs bindless
textures and surfaces, and PTX only allows texture and sampler handles
in registers in unified texture mode, so report an error on sm_2x and
for texture and sampler handles in independent texture mode instead of
emitting invalid PTX.
---------
Co-authored-by: mmalavika <mmalavika at nvidia.com>
Revert "[llvm-diff] Compare TBAA and alias scope metadata" (#243239)
Reverts llvm/llvm-project#238976
Looks like the new test broke because of a mid-air collision with
080bb047270d99b468db8ca9603ff1b320124eff.
[bazel][libc] Allow generated headers to be filtered by entrypoint (#243168)
For https://github.com/llvm/llvm-project/issues/242727. This PR splits
the `libc_generated_header` rule into two steps. Instead of directly
generating a header, we introduce two new rules: `libc_hdrgen_spec` and
`libc_generated_headers`. The former describes all the inputs to a
`hdrgen` invocation for a header without producing a file, and the
latter generates the header from the spec while letting you specify
`--entrypoints=`.
This is nice because it allows rules to share definitions for how
headers are produced while specifying their own sets of `entrypoints`.
---
**Note:** this is not exactly equivalent to how the CMake build works.
In this PR, LLVM-libc function objects are still compiled against
[unfiltered
headers](https://github.com/llvm/llvm-project/blob/cbfac21cd384f6c7c480c2d0026ecedfe2d619e7/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl#L46),
[23 lines not shown]
sysutils/Makefile: fix u-boot-cm3588-nas SUBDIR entry
The entry pointed to u-boot-cm3588, which does not exist, so poudriere
warned about a nonexistent origin and skipped it.
Mk/Scripts/create-manifest.sh: drop unused dp_ABISTRING check
Nothing sets dp_ABISTRING since the merge, so every package build
aborted in create-manifest. The script never uses it, and upstream
does not require it.
CGExprCXX: emit family and allockind attributes
This allows us to remove the special knowledge about C++ allocation from
LLVM's MemoryBuiltins.cpp, instead trusting attributes to communicate
the important properties.
Annoyingly, clang has to grow a little bit of hard-coded knowledge about
mangled symbol names in order to actually get the most-basic-matching
::operator::new when working out the alloc-family attribute. I spent
some time trying to do this "right" by looking up the available
operators new and finding the best one, but that's super tricky and this
has the virtue of working and being pretty obviously correct when
compared to the old code.
Happily, clang now emits allocator family attributes for custom
allocators like the `__hot_cold_t` overloads in `new_hot_cold.cpp`
(which `isReplaceableGlobalAllocationFunction` in clang recognizes),
allowing us to remove that special knowledge from LLVM.
[7 lines not shown]
SimplifyLibCalls: preserve allocation attributes in optimizeNew
When `LibCallSimplifier::optimizeNew` rewrites an `operator new` call into a
`__hot_cold_t` allocation call, forward the allocation attributes
(`allockind`, `allocsize`, `"alloc-family"`, and parameter `allocalign`) from
the original call onto the synthesized call instruction alongside its metadata.
This is a new patch since 2023 (unlike most of the rest of the stack)
and allows the next patch to remove more specialized C++ knowledge
from the LLVM layer, instead leaving it in clang where it seems more
sensible.
This patch was authored with the assistance of an LLM and was reviewed
by me before posting.
clang: emit allocalign to LLVM for alloc_align attributes
LLVM is growing knowledge of this, so we should inform it when we have
the information available. As a bonus, since we now check return
alignments in the callee as of an earlier patch of mine, we can now drop
the redundant llvm.assume() that this previously emitted.
This patch is originally from 2023 and was rebased and revised with
assistance from an LLM. I have manually reviewed the diffs to the
limit of my abilities (I don't do much in LLVM, and this is my first
time touching clang in a meaningful way) and they appear sensible. The
commit messages are entirely written by me.
Differential Revision: https://reviews.llvm.org/D119271
clang: also check alloc_align and assume_aligned claims in return
Prior to this patch, we only check alloc_align and assume_aligned claims
in the caller. We are about to thread alloc_align information down into
LLVM, which would then have a chance to defeat the sanitizer checks by
performing optimizations. To avoid that, we also check alignment claims
in the called function prior to return.
Per review feedback on D121629:
- Also verify the alignment required by `AssumeAlignedAttr` in
`EmitReturnValueCheck`.
- Add a new `ReturnAlignmentAssumption` (`return_alignment_assumption`)
sanitizer handler in clang and compiler-rt that accepts the dynamic
return statement `SourceLocation` pointer loaded from `ReturnLocation`.
- Only emit the sanitizer check (and not a redundant `llvm.assume`) in
`EmitReturnValueCheck`.
This patch is originally from 2023 and was rebased and revised with
assistance from an LLM. I have manually reviewed the diffs to the
[5 lines not shown]
[NFC] clang: simplify emitAlignmentAssumptionCheck (#239728)
Move the alignment check condition (`ptrtoint`, optional offset
subtraction, mask, and `icmp eq 0`) into
`CodeGenFunction::emitAlignmentAssumptionCheck` and emit the sanitizer
check before `Builder.CreateAlignmentAssumption`.
This removes the need to pass `TheCheck` and `Assumption` into
`emitAlignmentAssumptionCheck` (or temporarily unlink and re-insert
`Assumption`) and prepares `emitAlignmentAssumptionCheck` to be called
directly without an accompanying `@llvm.assume`.
This patch is new since this line of work was originally authored in
2023. It was largely written by an LLM in response to review feedback
for the next patch, but I hand-reviewed the content and it looks
reasonable enough (with the same disclaimer as other patches that I know
nothing about clang.)
[SLP]Fix copyable FP lanes changing NaN and subnormal bits
FP identity ops on copyable lanes may quiet NaNs and flush
subnormals. Keep such lanes only for FP math users, otherwise
blend the original values back.
Fixes #243130
Fixes #243217
Pull-request: https://github.com/llvm/llvm-project/pull/243243
devel/llvm1[89]-libs, llvm2[0-2]-libs: bump PORTREVISION
The GOLD option was removed to follow upstream, so these ports no
longer install LLVMgold.so. Bump PORTREVISION so the package change
is picked up.
Attributor: Use one check prefix in memory-location-writable.ll
Replace the tests with one function whose stored pointer is read back
at an unknown offset. It hits the conflict in attributor,
attributor-cgscc and attributor-light and gives the same output in all
three, so all RUN lines share one check prefix.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
devel/got: update to 0.131
User-visible changes:
- remove support for .cvsignore files
- always print a tab after the file name in unidiff headers, for Larry patch(1)
[flang-rt] Consume the whole field in B/O/Z input (#238057)
EditBOZInput reads a fixed-width field twice: the first pass counts the
significant digits, then it rewinds to the first significant digit and
the second pass decodes exactly that many digits. Nothing moved the
position back to the end of the field afterwards, so the next edit
descriptor started reading right after the last significant digit:
s = '1F XY'; read (s, '(z6,a2)') i, c ! c was ' ', not 'XY'
s = '1f,2'; read (s, '(z4,i2)') i, j ! j was 0, not 2
The second pass also called GotChar() again for each character it
re-read, so READ(SIZE=) counted the significant digits twice (8 instead
of 6 for '(z6)' on ' 1F ').
Record the position reached at the end of the first pass, which is past
any trailing blanks and any separator that ended the field early, and
return to it after decoding. Undo the SIZE= count of the re-read
characters.
[8 lines not shown]