[SimplifyLibCalls] Don't set nnan on synthesized frem in optimizeFMod (#199284)
LibCallSimplifier can fold a libcall to fmod to an frem instruction if
the fmod call doesn't set errno.
fmod(x, y) sets errno if x == +/-Inf or y == 0. The old code assumed
that this was also a sufficient condition to prove that the result is
not NaN, and so unconditionally set the nnan fmf on the new frem
instruction. That's not sound; e.g. fmod(x, NaN) == frem(x, NaN) ==
NaN.
We don't actually have to worry about propagating the `nnan` flag;
B.CreateFRemFMF does it for us automagically.
This bug was found by a large run of Opus 4.7 looking for bugs in LLVM.
[SimplifyLibCalls] Fix optimizeFdim for Inf-Inf cases (#199306)
fdim(x,y) is defined as
NaN if x or y is NaN, otherwise
(x > y) ? x - y : +0
optimizeFdim computed fdim(x,y) as max(x-y, +0). This is not correct
when x == y == +/-Inf; the result should be 0, but this optimization
returns NaN.
I was surprised by this bug because there's even a testcase checking the
incorrect behavior. But returning 0 matches the description in C99 and
POSIX, where, just to be extra clear, the spelling of the piecewise
function is
NaN if either input is NaN
x - y if x > y
+0 if x <= y
[4 lines not shown]
[clang] Fix crash in getCursorRawComments. (#199328)
Fix a regression introduced in PR #198452 where querying raw comments on
invalid cursors caused a segmentation fault due to unconditional
ASTContext lookup. Adding an early exit for unsupported cursor kinds at
the top of getCursorRawComment safely avoids resolving the context on
invalid cursors with null translation units.
[LV] Determine NumPredStores before computing widening costs. (#199341)
Determine NumPredStores before computing widening costs, so we
consistently apply large predicated store cost to all stores, matching
the VPlan cost model. In practice that should not impact vectorization
decisions, as the huge cost for any predicated store other than the
first already effectively disables vectorization.
[Analysis][AIX] Add !implicit.ref globals as ThinLTO summary ref edges to support pragma comment(copyright) LTO interaction
Teach ModuleSummaryAnalysis to include globals referenced via
!implicit.ref metadata as explicit reference edges in the ThinLTO
module summary via a new helper findImplicitRefEdges.
[PowerPC][AIX] Support #pragma comment copyright for AIX
- Emit !aix.copyright.comment from Clang for the pragma.
- Lower it in LLVM to a TU-local string + llvm.used + !implicit.ref.
- Add module-import and backend relocation tests.
[libc++][test] Merge test files for `mdspan::at` (#199330)
`libcxx/test/libcxx/containers/views/mdspan/mdspan/assert.at.pass.cpp`
caused build bot failures for
- sanitizer-aarch64-linux-bootstrap-asan
- sanitizer-aarch64-linux-bootstrap-hwasan
- sanitizer-aarch64-linux-bootstrap-msan
It's not yet clear why current mechanisms don't work for these builds.
`TEST_HAS_NO_EXCEPTIONS` should have been working.
Also remove one unnecessary `static` and use `std::string_view(e.what())
== "mdspan"`.
[DAG] UDIV/SDIV exact nodes support DemandedElts + add test (#198715)
Resolves #183047
This patch updates isKnownNeverZero to handle DemandedElts for UDIV and SDIV exact nodes.
[clang-doc][nfc] Avoid combining constexpr with std::initializer_list as this seems to give MSVC trouble. (#199311)
Some Windows bots using MSVC 2019 and 2022 get assertion errors in the
clang-doc lit tests (see
[here](https://github.com/llvm/llvm-project/pull/198066). This seems to
be due to MSVC having trouble with a correctly initializing structures
using std::initializer_list when embedded in a struct declared with
constexpr.
This workaround changes constexpr to const in a struct definition to
avoid this issue.
[X86] combineVectorInsert - use generic zext/shift/or pattern for constant concatenation (#199344)
Generalised the code added in #198273 to make it easier to support other
combos in future patches.
Hopefully we can get load combining to work here soon.
[libc++][test] Make `copy_move_types.h` usable in old modes (#199183)
This PR makes types in `copy_move_types.h` usable in C++03/11 modes.
Because it is discovered that some types in `copy_move_types.h` are
useful for testing uninitialized memory algorithms in pre-C++20 modes.
[NVPTX] Auto-upgrade llvm.nvvm.abs with int-min poison (#198646)
Update the auto-upgrade for llvm.nvvm.abs.i and llvm.nvvm.abs.ll to use
the generic llvm.abs intrinsic with is_int_min_poison=true. The previous
expansion used neg/icmp/select which gives defined INT_MIN -> INT_MIN
behavior, but loses the poison/undefined signed-min semantics needed for
NVPTX to select PTX abs.s32 and abs.s64 instrucitons when the source
operation permits signed-min overflow to be undefined. This is a
followup to #183851 . Using llvm.abs(..., true) preserves intended IR
semantics and lowers through the new ABS_MIN_POISON. We also update the
tests and add NVPTX CodeGen coverage for the legacy nvvm abs intrinsics.
[CIR] Attach noreturn attribute to __cxa_bad_cast (#198727)
## Summary
- Mark `__cxa_bad_cast` as `noreturn` in CIR, mirroring the existing
`__cxa_bad_typeid` handling. The attribute is now set on every `CallOp`
that targets it,
covering both the CodeGen direct path (`emitCallToBadCast`) and the
target-lowering path (`buildBadCastCall`).
- Drop the now-fulfilled `MissingFeatures::opFuncNoReturn` entry and
the corresponding TODO/assert at the lone caller in
`LowerItaniumCXXABI.cpp`.
- Update FileCheck expectations in `dynamic-cast.cpp`,
`dynamic-cast-exact.cpp`, and `abi-lower-after-unreachable.cpp` to
require the `{noreturn}` attribute on the lowered
`cir.call @__cxa_bad_cast()`.
[libc++][test] Add backported `destroy({_at,_n})` for tests (#199185)
It would be convenient to use `destroy_at`, `destroy`, and `destroy_n`
in tests for pre-C++17 uninitialized memory algorithms. So this PR add
backported versions of them for tests.
[CIR] Extract CIR_ClassCastOp base class for BaseClassAddrOp and DerivedClassAddrOp
Both ops have identical structure (arguments, results, assembly format)
and differ only in mnemonic and description. Extract a shared TableGen
base class to eliminate the duplication. Also improve the assembly format
to print nonnull before the operand and place the type after the offset.
[CostModel][X86] Update VECREDUCE MINMAX costs based off llvm-mca analysis (#199208)
Add full CostKinds, to improve a lot of reduction matching in
vectorcombine/slp passes
These are based off SMIN/UMIN numbers, and a few SMAX/UMAX numbers don't
always match, but are typically within +/-1
[CIR] Extract CIR_ClassCastOp base class for BaseClassAddrOp and DerivedClassAddrOp
Both ops have identical structure (arguments, results, assembly format)
and differ only in mnemonic and description. Extract a shared TableGen
base class to eliminate the duplication. Also improve the assembly format
to print nonnull before the operand and place the type after the offset.
[clang] Fix crash in getCursorRawComments.
Fix a regression introduced in PR #198452 where querying raw comments on invalid cursors caused a segmentation fault due to unconditional ASTContext lookup. Adding an early exit for unsupported cursor kinds at the top of getCursorRawComment safely avoids resolving the context on invalid cursors with null translation units.
[RISCV][GlobalISel]Implement support for vector calling convention with fixed length vectors (#199227)
Implementing IRTranslator support for fixed length vectors when the V
extension is used. This implementation works similar to SelecionDAGs. We
use insert and extract subvector OPs to get the fixed length vectors out
of the scalable length vectors.
[libc][math] Add iscanonical functions to math.yaml
Surface the existing iscanonical, iscanonicalf, iscanonicalf128, iscanonicalf16, and iscanonicall
implementations through the generated math.h.
To test:
`cmake -Bbuild -Sruntimes -GNinja -DLLVM_ENABLE_RUNTIMES=libc -DLLVM_LIBC_FULL_BUILD=ON`
`pip install pyyaml`
`ninja -C build libc.include.math.__generated_hdr__`
Then check `build/libc/include/math.h` for their signatures.
Add `-DLIBC_TYPES_HAS_FLOAT128=ON` to test for iscanonicalf128
in cmake invocation if host does not support it.
And `-DLIBC_TYPES_HAS_FLOAT16=ON` for iscanonicalf16.
[libc][math] Add iscanonical functions to math.yaml
Surface the existing iscanonical, iscanonicalf, iscanonicalf128, iscanonicalf16, and iscanonicall
implementations through the generated math.h.
To test:
`cmake -Bbuild -Sruntimes -GNinja -DLLVM_ENABLE_RUNTIMES=libc -DLLVM_LIBC_FULL_BUILD=ON`
`pip install pyyaml`
`ninja -C build libc.include.math.__generated_hdr__`
Then check `build/libc/include/math.h` for their signatures.
Add `-DLIBC_TYPES_HAS_FLOAT128=ON` to test for iscanonicalf128
in cmake invocation if host does not support it.
And `LIBC_TYPES_HAS_FLOAT16=ON` for iscanonicalf16.
[libc][math] Add iscanonical functions to math.yaml
Surface the existing iscanonical, iscanonicalbf16, iscanonicalf, iscanonicalf128, iscanonicalf16, and iscanonicall
implementations through the generated math.h.
To test:
`cmake -Bbuild -Sruntimes -GNinja -DLLVM_ENABLE_RUNTIMES=libc -DLLVM_LIBC_FULL_BUILD=ON`
`pip install pyyaml`
`ninja -C build libc.include.math.__generated_hdr__`
Then check `build/libc/include/math.h` for their signatures.
Add `-DLIBC_TYPES_HAS_FLOAT128=ON` to test for iscanonicalf128
in cmake invocation if host does not support it.
And `LIBC_TYPES_HAS_FLOAT16=ON` for iscanonicalf16.