[LoongArch][NFC] Move XOR combine into performXORCombine
Extract the inline ISD::XOR handling in PerformDAGCombine into a
dedicated performXORCombine helper, matching how the other opcodes
(AND, OR, SETCC, ...) are structured. No functional change.
Also fix a clang-format issue in emitPseudoVMSKCOND.
Assisted-By: LLM
Revert "[DwarfDebug] Add applyDwarfVersion() so the targets like NVPTX can recompute the version-derived state" (#242150)
Reverts llvm/llvm-project#234510 as this PR introduce build breakage on
pre/post submit builders.
[DAGCombiner] Rebuild FMA chain instead of mutating it in place (#241188)
visitFADDForFMACombine folds
fadd (fma A, B, (fmul C, D)), E --> fma A, B, (fma C, D, E)
by replacing the inner fmul in place with ReplaceAllUsesOfValueWith.
If fma A, B, (fma C, D, E) already exists, e.g. when another expression
adds the same terms in a different order, CSE merges the updated chain
into it and the outer fadd becomes
fadd (fma A, B, (fma C, D, E)), E
The combine returns this outer fadd, retaining the extra addition of E.
If an identical fadd already exists, the outer fadd is CSE'd away while
being visited.
Rebuild the chain with getNode instead, and drop the DELETED_NODE check
in visitFADD.
[InferAddressSpaces] Infer constant addrspacecast operands
A cast back from the flat address space folds into a constant
expression when its operand is constant. Only AddrSpaceCastInst and
memory operands were visited, so such a cast used as a call argument
or a stored value kept its round trip through the flat address
space.
Visit constant expression operands of a specific address space.
Change-Id: Iab1aaaf809a41f48886d0412cdb96d756e5e86c5
Co-Authored-By: Claude Fable 5.2 <noreply at anthropic.com>
[NFC][LowerTypeTests] Write export summaries to %t.out (#242134)
#221090 switched these tests from split-file to writing the summary to
%t. Incremental builds that ran the old tests still have %t as a
directory and fail with "Is a directory". Use %t.out so the tests work
in such builds, including incremental bisects across #221090.
Assisted-by: Gemini
[LoongArch] Select [X]VBITSELI_B for byte splat bitsel on wider element types
The VBITSELI_B/XVBITSELI_B patterns only matched v16i8/v32i8. When the
bitwise select idiom `(a & imm) | (~a & b)` appears on v8i16/v4i32/v2i64
(or the LASX equivalents) with a byte splat constant, e.g. from portable
SIMD implementations of the bitseli intrinsics, we emitted:
```
vrepli.b $vr2, 127
vbitsel.v $vr0, $vr1, $vr2, $vr0
```
Use vsplat_i8_uimm8, as VANDI_B/VORI_B/etc. already do, so that we now
emit:
```
vbitseli.b $vr0, $vr1, 127
```
Assisted-By: LLM
[LoongArch][NFC] Add tests for vector bitwise selection with byte splat immediates
Add tests for bitwise selection on non-i8 element vectors where the
select-constant is a byte splat, which could be selected to
VBITSELI_B/XVBITSELI_B.
Assisted-By: LLM
[asan] Scan fake stack allocation flags eight at a time (#242047)
After every noreturn call (throw, longjmp, ...) the next fake frame
allocation runs FakeStack::GC, which looks at the allocation flag of
every frame of every size class, one byte at a time: about 33,000 flags
for the default fake stack size. Usually few frames have their flag set,
so nearly all of that work is reading zeros.
Skip eight clear flags per load. LeakSanitizer's ForEachFakeFrame had a
copy of the loop; both now share ForEachAllocatedFrame. What is
collected and what is scanned for leaks does not change.
This helps programs that throw or longjmp often. libpng leaves every bad
input by longjmp: on x86_64 Linux, replaying a fuzzing corpus through
its read target takes 0.57 of the instructions and about 0.8 of the CPU
time. A plain longjmp or throw loop takes 0.3 to 0.9 of the time,
depending on the size of the frames, the depth and how long it has run.
The instruction count of 18 other workloads stays within 0.05%.
[7 lines not shown]
[Support] Vectorize the byte scan in StringRef::rfind(StringRef)
StringRef::rfind(StringRef) forwards to std::string_view::rfind. libstdc++
compares the whole needle with memcmp at every position; libc++ scans
backwards for the needle's last character one byte at a time. Neither is
vectorized, and there is no portable memrchr to call instead.
Scan backwards for the needle's first character 16 bytes at a time, with a
branch-free OR of compares per chunk that clang and GCC turn into one vector
compare and mask test, and compare the rest of the needle only where the
character occurs.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
Claude-Session: https://claude.ai/code/session_01TvfuMmXF8ywTFaZFX8JuGM
Reapply "[llvm-strings] Add --encoding={s,S,utf8} option (#221794)" (#241881)
This reverts commit 3a99f8bbe76805586c0247eba38b907bb8400dcb and fixes
the macOS iconv detection that prompted the original removal.
[Clang][CFI] Don't let -fdevirtualize-speculatively force llvm.type.checked.load (#241643)
9e7ce77573b2 (#159685) made `-fdevirtualize-speculatively` override both
conditions for emitting `llvm.type.checked.load`:
`-fwhole-program-vtables`
and hidden LTO visibility of the class. The override never helped
speculative devirtualization, because that pass only runs without LTO,
and CFI requires LTO.
With LTO and trapping `cfi-vcall`, the override adds a local CFI check
to
classes with public LTO visibility. That check only knows the vtables in
the current LTO unit, so it traps on valid objects created elsewhere,
such as `std::exception` subclasses from the shared C++ runtime or
classes from other DSOs. With `-fsanitize-cfi-cross-dso`, these calls
also skip `__cfi_slowpath`.
Remove the override.
[3 lines not shown]
[DwarfDebug] Add applyDwarfVersion() so the targets like NVPTX can recompute the version-derived state (#234510)
`DwarfDebug` derives several settings such as DWARF64, accelerator table
kind, GNU TLS opcode, DWARF2
bitfields, segmented string offsets, .debug_macro, MinimizeAddr, and the
MCContext version and format from the DWARF version in its constructor.
A target that overrides the version after construction could change only
the MCContext value, leaving the rest
derived from a different version.
This change refactors this version-derived state into
`DwarfDebug::applyDwarfVersion(unsigned)`, called by the constructor and
callable again by a target subclass. The version-independent part of the
constructor is unchanged.
`NVPTXDwarfDebug`, which always emits DWARF v2, calls this function to
set version 2.
This fixes a module with no "Dwarf Version" flag getting a v2 header
with v4 encodings (DW_AT_data_bit_offset instead of DW_AT_bit_offset).
[3 lines not shown]
[Index] Report references through UsingType (#228823)
namespace ns2 { using ns1::A; }
ns2::A a;
`ns2::A` is a UsingType. TypeIndexer has no VisitUsingTypeLoc and
RecursiveASTVisitor only traverses the qualifier, so the reference to A
has been dropped since UsingType was introduced (af27466c5039). This
affects clangd's find-references and index, as well as other
clangIndex users like ccls.
Report the target declaration, similar to DeclRefExpr. For a typedef
target used as a base specifier, also report the implicit reference to
the class, like VisitTypedefTypeLoc.
Aided by Opus 5.5
[clang][PAC] Fix crashes on _Atomic __ptrauth-qualified objects (#240294)
Implicit `_Atomic` operations on a `__ptrauth`-qualified object assert
in CodeGen, because the pointer-authentication helpers do not look
through `AtomicType`: https://godbolt.org/z/6KE7Ez5P4 (a trunk build, so
the link stops crashing once this lands).
Fix the crashes. In a build without assertions the same code miscompiled
an `_Atomic` function pointer under `-fptrauth-calls`, signing it twice
or leaving it unsigned. Nothing else changes: the tests simply document
current behavior, with a FIXME on what I propose fixing in follow-ups,
for example https://godbolt.org/z/hGosq14ea.
Assisted-by: AI
[DSE][AMDGPU] Remove dead LDS writes at wave exit
LDS is freed once every wave of a work-group has terminated, and a
wave terminates when its entry function returns. Other waves can only
observe its LDS writes through a synchronizing operation. DSE still
kept every such write, because it treats LDS like any other global.
Add a TTI hook that reports address spaces whose writes cannot be
observed once a function returns, and let DSE treat globals in them
like allocas at function exit. AMDGPU reports LDS in entry functions.
Loads, barriers, fences, atomics and calls still keep earlier writes.
Change-Id: I3147eae461cf85e9e1f15d5626266c496fb4c430
Co-Authored-By: Claude Fable 5.2 <noreply at anthropic.com>
[DSE][AMDGPU] Add LDS store-at-exit tests (NFC)
DSE keeps LDS writes that nothing reads or synchronizes before an
entry function returns. Record the current behavior before changing
it.
Change-Id: If7c568ce3aec9e7fe847fccd6698ac71733b2364
Co-Authored-By: Claude Fable 5.2 <noreply at anthropic.com>
CodeGen: Share atomic libcall selection between the legalizers (#239083)
SelectionDAG and GlobalISel each had their own copies of the choice
between an outline atomic and a __sync_* call. Move it into a common
helper.
The __sync_* call is now always looked up in the DAG's libcall info,
rather than sometimes in the TargetLowering defaults. Also disable
the untested __sync call case in GlobalISel.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[Clang][CFI] Don't report sanitizer stats for unchecked VFE loads (#241641)
With virtual function elimination (3b598b9c867a),
`EmitVTableTypeCheckedLoad` is also used for calls that have no
`cfi-vcall` check, such as calls in `no_sanitize("cfi-vcall")` functions
or on ignorelisted classes. It reported `-fsanitize-stats` for these
calls anyway, so the stats counted checks that were never performed.
Report stats only when the check is emitted.
Assisted-by: Gemini