[NFC][Clang] Remove dead code from LifetimeSafety/FactsGenerator.cpp (#210830)
This PR removes dead code in
`clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp`. This was
discovered by a Coverity scan on clang.
clang/AMDGPU: Stop passing redundant -target-cpu to cc1
Now that the exact target is encoded in the triple's subarch field,
-target-cpu is redundant. This avoids polluting the resultant IR with
unwanted "target-cpu" attributes. The net result is the desired codegen
when compiling libraries for a major subarch and linking it into a
program compiled for a specific arch. e.g., compiling for "gfx9-generic"
would pollute the IR with "target-cpu"="gfx9-generic", so codegen
would ultimately be performed for the generic target even after
linking into the concrete gfx9 cpu. The specialization will now be
achieved by merging the triples without the linker or optimization
passes needing to fixup function attributes.
clang: Start using new amdgpu subarch triples
Fixup invocations using --target=amdgcn + -mcpu to introduce
the subarch in the triple.
For offload toolchains, a single toolchain is constructed for the
top level amdgpu architecture, and the effective triple is used for
target specific tool invocations.
The specifics of the resource directory layout are tbd. This does
try to find resources in the subarch named directory. The paths
are searched at toolchain creation time, so that does not work
when there are multiple subarches.
Fixes #154925
Fix Strong VTables Accidentally Emitted by #159856 (#200942)
Users have reported link errors due to duplicate vtables after the merge
of #159856. Root cause analysis revealed that these errors were due to
the VTables emitted in `CGOpenMPRuntime::emitAndRegisterVTable`, which
was added by PR #159856. This PR fixes the issue by changing that
function to emit its VTables as weak symbols.
AMDGPU: Constant fold instructions with inline immediate operands (#208422)
Previously we would only try to perform constant folding and
simplifications when an immediate was folded into an instruction,
not if the input was already a folded constant.
Co-authored-by: Claude (Opus 4.8) <noreply at anthropic.com>
AMDGPU: Do not report inline immediates as legal for generic operands (#208216)
This has one test change in an SI_CS_CHAIN_TC* test. Either this is fine
or the instruction definition should be changed.
[CIR] Add x86_64 aggregate calling-convention lowering (#210528)
The x86_64 SysV calling-convention bridge in CallConvLowering so far handles only scalar arguments and returns. A function with a struct or array parameter is reported NYI. This teaches the bridge to classify struct and array aggregates.
A struct is mapped to an `llvm::abi` record built from the DataLayout field offsets and the CanPassInRegisters flag on the module's `cir.record_layouts` metadata, and an array maps to an `llvm::abi` array. The library's classifier then produces the ArgInfo, either Direct with a coerced register type the existing rewriter flattens, or Indirect via sret, byval, or byref. CIRABIRewriteContext already applies all of these, so this only feeds it the aggregate classifications and leaves the scalar path untouched.
Aggregate shapes the bridge does not yet classify stay errorNYI, so an unsupported signature fails cleanly instead of being misclassified. Those are unions (whose register coercion needs a widen fixup), packed and over-aligned records, empty-for-ABI records, and `_BitInt`. All-float aggregates such as a two-`float` struct or `float[2]` are included too. Their SSE class coerces to a `<2 x float>` vector the bridge cannot yet represent, so instead of passing the aggregate through unchanged it reports the coercion as NYI.
The byval and sret argument attributes still carry the CIR record type. Converting that to the LLVM type in LowerToLLVM is a separate change, so the byval and sret tests check the CIR output only, while the direct and flatten tests also check the lowered LLVM IR.
[GVN] Restructure `GVN.h` to reduce its size (NFC)
* Rename `GVNPass::ValueTable` to `GVNValueTable`, and move it out to
the `llvm` and to its own file `GVNValueTable.h` (the type is also
used by `GVNHoistPass` and it makes sense to have it in a separate
file instead of `GVNHoistPass` peeking into `GVN.h`).
* Move `GVNPass::Expression` into `llvm::GVNValueTable`.
* Move `DepKind`, `ReachingMemVal`, and `DependencyBlockInfo` to `GVN.cpp`.
* Move `GVNHoistPass` and `GVNSinkPass` to their own headers.
[GVN] Reorganise GVN.h/GVH.cpp to improve readability and maintainability (NFC)
Over the years GVN.h/GVN.cpp has grown in size and complexity, and the order of
member functions and definitions has become somewhat arbitrary. This commit
reorganises the code to improve readability and maintainability.
* in `GVNPass` class, put private member variables first, followed by public
member functions, and then private member functions
* in `GVNPass` class: private type definitions are placed in front of the
logically related member variables (except `ValueTable` which need to be
public)
* definitions of `GVNPass::ValueTable` methods are grouped and reordered to
match the order of their declarations
* The following `GVNPass` member functions were made `private` and `LLVM_API`
removed: `getDominatorTree`, `getAliasAnalysis`, `getMemDep`,
`isScalarPREEnabled`, `isLoadPREEnabled`, `isLoadInLoopPREEnabled`,
`isLoadPRESplitBackedgeEnabled`, `isMemDepEnabled`, `isMemorySSAEnabled`,
and `salvageAndRemoveInstruction`
* `constructSSAForLoadSet` changed to take a `Dominator &`, in order to not
[12 lines not shown]
[OpenACC] Make sure our 'init' recipe handles nullptr_t (#211008)
The bug report shows that we missed one scalar type in our
initialization code, nullptr_t! This patch adds the initializer to make
sure it works correctly, and adds the test (plus a non-template
version).
Fixes: #210877
[OpenACC] Better handle error overloaded ops in ForStmtChecker (#211005)
The OpenACC 'loop' constructs do a bunch of checking on the contents of
a ForStmt. However, in cases of overloaded operators, some of the
checking we assumed happened (like operators having a certain number of
args) doesn't hold in the case of errors. This patch adds some
guards to make sure we error-out if the number of args doesn't match
what we're expecting everywhere I could find it.
Fixes: #210958
[MLIR][Linalg] Fix FlattenElementwiseOp for linalg.broadcast (#210738)
Follow-up of https://github.com/llvm/llvm-project/pull/207005
The added test 'unsupported_dim_expanding_broadcast' passed with
broadcast-like 'linalg.generic' but failed with a 'linalg.broadcast'.
Generating an incorrect `linalg.collapse_shape` raising error `op number
of elements must be preserved` upon flattening. This patch prevents
broadcasting ops to be targeted by this op while allowing 0-D to N-D
broadcasting to take place as for linalg.fill.
I removed the negative test
`unsupported_rank_expanding_broadcasting_elementwise` as it had been
mentioned in the previous MR that it was repeating the above
`unsupported_broadcasting_elementwise` test.
[lld][WebAssembly] Preserve segment linking flags in --relocatable output (#210747)
`OutputSegment::addInputSegment` copied each input chunk's alignment but
never its flags, so a relocatable link serialized `flags=0` for every
data segment and dropped `RETAIN` and `STRINGS`. Losing `RETAIN` let the
final default `--gc-sections` link discard runtime-registered sections
such as Swift's `swift5_*` metadata, corrupting the program. This unions
each input segment's flags into the output segment's `linkingFlags` and
adds a `lld/test/wasm` test covering `RETAIN`, `STRINGS`, and flag
accumulation across coalesced segments.
Resolves
https://github.com/swiftlang/swift-package-manager/issues/10314.
[Clang] Yet more consistent Unicode diagnostics (#211002)
This PR
- Use the recently introduced `EscapeSingleCodepointForDiagnostic` in
more places
- Fix a bug where U+FEFF was incorrectly treated as a BOM and therefore
did not render at all in diagnostics
[libc++][ranges] Mark LWG3664 as resolved (#210550)
Closes https://github.com/llvm/llvm-project/issues/105066.
When libc++ implemented `ranges::distance` in
c965d5448ecdf9a5513983862a78a2ba8f7fbab8, LWG3664 was implemented
together. The patch additionally changed cast result type from `const
decay_t<I>&` to `decay_t<I>`, which partially implemented LWG4242.
Currently, we are using `iter_difference_t<_Ip>` as the return type of
one `operator()` overload while LWG3664 modified that overload to return
`iter_difference_t<decay_t<_Ip>>`. The change is NFC because when
`iter_difference_t<decay_t<_Ip>>` is valid, `iter_difference_t<_Ip>` is
also valid and denotes the same type.
References:
- https://wg21.link/LWG3664
- https://eel.is/c++draft/range.iter.op.distance
[2 lines not shown]
[clang][AArch64] Set hardening fn attrs on synthetic functions
Compiler-synthesized functions such as `__llvm_gcov_writeout`,
`__llvm_gcov_reset` and `__llvm_gcov_init` were previously never receiving the
AArch64 hardening function attributes (ptrauth-returns, ptrauth-auth-traps,
ptrauth-indirect-gotos and aarch64-jump-table-hardening) since the
attributes were only emitted by Clang and gated by `PointerAuthOptions`
structure's corresponding fields. See `setPointerAuthFnAttributes` and
`initPointerAuthFnAttributes` member functions of `TargetCodeGenInfo`.
This patch resolves this in the same manner as #83153 does for several
other attributes. Particularly, Clang now emits corresponding 4 module
flags (conditionally on whether the related feature is enabled) with Max
behavior, and LLVM's `Function::createWithDefaultAttr` derives the matching
function attributes from them. Max behavior with conditional emission is
safe because none of these features affect ABI, so promoting an absent
flag on module merge cannot break compatibility.
[DAGCombiner] Fold NaN-guard fptosi/fptoui select to saturating variant (#201435)
Fold select (setcc X, 0, SETUO), 0, (fp_to_sint/fp_to_uint X) to
fp_to_sint_sat/fp_to_uint_sat in the generic DAG combiner, gated by
shouldConvertFpToSat. Also handles the SETO form with swapped arms, and
looks through an AND mask on the conversion result. Lit tests added for
AMDGPU and AArch64.
Assisted-by: Claude Code
AMDGPU/GlobalISel: Clean up fp LLT usage in AMDGPULegalizerInfo (#210999)
Remove local variables in favor of global F16/BF16/F32/F64/V2F16/V2BF16.
These are now proper floating point LLTs instead of LLT::scalar.
A couple of legalizer actions now use fp extended LLT for type checks.
This is intended and is planned for all floating point opcodes.
In most cases the current S16/S32/S64 action on floating point opcodes was
intended for F16/F32/F64, and we will need to define an action for BF16.
[Clang] Defaults `-Wunicode-whitespace` to an error. (#210945)
Clang accepts some Unicode whitespaces in some context. There are a few
issues with this:
- The support is incomplete and inconsistent, as illustrated in #38934
- We are not consistent with the Unicode specs (tr1, tr55) in that we
treat U+0028/0+0029 as horizontal separators while Unicode consider them
vertical.
Ultimately, Unicode whitespaces are more likely than not unintended.
Neither GCC nor MSVC support this extension.
Fixes #38934.
[SCEV][NFC] Precommit tests for MatchRangeCheckIdiom through zext (#210978)
'zext(X - 1) ult C' => 'X in [1, C+1)';
also ugt case (wrapping range)
Alive2 proof: https://alive2.llvm.org/ce/z/zcdv_2
[libc++] Don't require complete types in vector<T>::empty() (#210754)
This was previously not required, but the patch to introduce a new
size-based vector layout unintentionally added this new requirement. We
almost certainly not want to promise this guarantee going forward, but
we should actually land this change explicitly and consider the
transition story, not do it as a fallout of another refactoring.
Fixes #210732
[GlobalISel] Use correct fp semantics when building constants. (#210190)
This bug can materialize as a `bfloat 1.0` becoming `0x3C00` which is
the bit pattern for `half 1.0`. After this change, `0x3F80` is correctly
returned.
The fix is to use the destination type to convert the provided
constant's semantics in `buildFConstant`. Added a unit test.
Removed `getAPFloatFromSize`, no more users.
[DirectX] Add slim debug support (#204459)
When DXC is called with `/Zs` flag, it emits "slim" debug info. It means
that ILDB section is omitted from the main DXContainer output and from
the output PDB file.
This patch reimplements similar behavior in llc, introducing
`--dx-slim-debug` flag.
[flang][OpenMP] Add semantic checks for two DECLARE VARIANT restrictions (#209528)
Diagnose two DECLARE VARIANT restrictions from the OpenMP specification
(5.2 [7.5], 6.0 [9.6]) that were previously accepted without error:
- If a procedure is determined to be a function variant through more
than one DECLARE VARIANT directive, the construct selector set of their
context selectors must be the same.
- A procedure determined to be a function variant may not be specified
as a base function in another DECLARE VARIANT directive.
Assisted-by: Cursor