[clang-repl] Undo the enumerators of an unscoped enumeration (#228370)
The enumerators of an unscoped enumeration are in the lookup table of
the enclosing context. Undoing the input that declared the enumeration
removed the enumeration, but its enumerators stayed visible:
```
clang-repl> enum E { Red };
clang-repl> %undo
clang-repl> int Red = 5;
error: redefinition of 'Red' as different kind of symbol
```
`ASTDeclUnmerger` now also visits the declarations of an undone
enumeration definition.
**Test:** new lit test `code-undo-enumerators.cpp` with three cases: an
enumerator reused as a variable, an enumeration redefined, and an
enumeration in a namespace. It checks printed values only, not
[7 lines not shown]
[mlir][nvgpu] Expose which memrefs optimize-shared-memory can swizzle (NFC) (#237180)
Extract checks on a memref's type out of
`optimizeSharedMemoryReadsAndWrites` into a new public function,
`canSwizzleSharedMemoryType`. The function would be helpful for prior
passes to reason about optimization decisions based on whether it is a
valid swizzling candidate.
Assisted-by: Claude
[ASan][test] Mark Linux/stack-overflow-recovery-mode.cpp UNSUPPORTED on Android AArch64 (#240097)
Temporarily mark `TestCases/Linux/stack-overflow-recovery-mode.cpp`
unsupported on Android AArch64 while waiting for #236879, matching
#236884 (https://lab.llvm.org/buildbot/#/builders/186/builds/4079).
Assisted-by: Gemini
[ADT] Add LLVM_ATTRIBUTE_WARN_UNUSED to SmallPtrSet (#240080)
This patch adds LLVM_ATTRIBUTE_WARN_UNUSED to SmallPtrSet so that
compilers can diagnose unused SmallPtrSet variables even though
SmallPtrSet has a non-trivial constructor and destructor.
This patch also addresses the existing warnings uncovered by the
attribute:
- ScheduleDAGSDNodes::BuildSchedUnits had an unused local variable
Visited, which this patch removes.
- SmallPtrSetTest.cpp intentionally leaves Other unused in two move
tests, so this patch marks Other with [[maybe_unused]].
Assisted-by: Antigravity
[LLVM] FIx fallout from #239908 (#240096)
The original patch added LLVM_ATTRIBUTE_WARN_UNUSED to some ADT classes,
which caused some more -Wunused-variable warnings under release builds
(that optimize out asserts).
https://lab.llvm.org/buildbot/#/builders/228/builds/17397
[clang][Sema][NFC] Share member template instantiation lookup (#239450)
Use `RedeclarableTemplateDecl` to consolidate the identical
`isInstantiationOf` implementations for class and function templates,
leaving the other overloads unchanged.
I initially considered turning these helpers into a function template,
but the declaration types use different accessors, such as
`getInstantiatedFromMemberTemplate()` and `getInstantiatedFromMember()`.
I'd also like to discuss whether a function template would be preferable
here, although that would likely require a broader change.
BPF: Stop lowering unwinding through nonexistent unwinder calls (#239899)
BPF borrowed the DWARF EH pipeline in an unsound way. DwarfEHPrepare
turned resume into a call of _Unwind_Resume, which will never be
linked in. BPFUnwindLower later replaced it, and calls of
_Unwind_RaiseException, by matching callee names after register
allocation. This fixes the pass pipeline relying on these transient
calls to phantom functions.
Instead add an invokable llvm.bpf.unwind.exit intrinsic, similar to
wasm's throw intrinsics. BPFUnwindPrepare replaces resume with it so
no impossible call to _Unwind_Resume reaches selection.
The intrinsic selects to a pseudo which BPFUnwindLower turns into
either unwind_exit or a branch to the landing pad when invoked. The
pseudo clobbers nothing, so register allocation can be more aggressive
than when the function looked like an ordinary call.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[SPARC] Remap the parameter DBG_VALUEs of a leaf procedure (#239545)
A leaf procedure stays in its caller's register window, so
remapRegsForLeafProc rewrites %i0-%i7 to %o0-%o7. PEI calls it from
determineCalleeSaves, while the parameter DBG_VALUEs at the start of the
entry block are stashed outside the function (stashEntryDbgValues), so
they keep naming %i registers and gdb reads the arguments of leaf
functions from the wrong register.
This renames the debug operands that are left once PEI has put the
stashed values back, in processFunctionBeforeFrameIndicesReplaced. Other
DBG_VALUEs on the same value were already renamed, it's only the stashed
parameter ones that were missed.
Fixes #235238.
`leaf.c` from the issue, `break get` in gdb, before:
```
[13 lines not shown]
[SPARC] Expand f64 bitcasts from v2i32 on 32-bit SPARC (#234201)
It is not possible to directly transfer values from integer registers to
floating point registers, so it needs to be done via the stack.
Fixes the following error:
LLVM ERROR: Cannot select: t10: f64 = bitcast t16
t16: v2i32 = BUILD_VECTOR t2, t4
t2: i32,ch = CopyFromReg t0, Register:i32 %0
t4: i32,ch = CopyFromReg t0, Register:i32 %1
In function: v2i32_build_vector
Assisted-by: Claude
[SPARC] Preserve register operand flags in BPR branch conditions (#240077)
parseCondBranch() rebuilt the register operand of a branch-on-register
(BPR) instruction from just its register number, and insertBranch()
re-added it with addReg(), so any operand flags were lost when a branch
was analyzed and reinserted.
When the register is undef (ProcessImplicitDefs marks the use undef
after removing its IMPLICIT_DEF), PHI elimination splitting a critical
edge rewrites the terminator via updateTerminator() and the BPR ends up
reading a virtual register with no def. The machine verifier rejects
this, and without the verifier the greedy register allocator segfaults
in VirtRegAuxInfo::weightCalcHelper.
Copy the whole MachineOperand into Cond and add it back with add(), as
other targets do.
Fixes #233111
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[NVPTX] Select scalar_to_vector for bf16x2 (#236706)
Fixes #235368.
DAG combining can create a v2bf16 SCALAR_TO_VECTOR for byte-vector
concatenations, including copies of unaligned bfloat values through
local arrays. NVPTX treats the node as legal but lacks a selection
pattern.
Pack the bf16 value into the low half of a 32-bit register and zero the
unspecified high half, as already done for v2f16. Add regression
coverage for direct packing, unaligned loads, and the original
local-array copy.
[libc] Use a syscall wrapper for remap_file_pages
This PR move remap_file_pages behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md.
[libc] Use a syscall wrapper for posix_madvise
This PR move posix_madvise behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md.
[VPlan] Factor out VPSCEVExpander::canExpandInIR (NFC). (#240063)
Split off the check for expressions that are expanded in IR and hoisted
out of HoistOutOf, to reuse it in follow-ups.
[LV] Remove InnerLoopVectorizer (NFC) (#240055)
All that is left of InnerLoopVectorizer is a bundle of state passed to
executePlan, of which only the assumption cache, a fresh IRBuilder and
whether runtime checks were generated are used, plus fixVectorizedLoop,
which runs legacyCSE on the vector loop header.
Create the IRBuilder in executePlan, take the assumption cache from
Legal, pass whether there are runtime checks as a bool and run legacyCSE
directly. Also drop executePlan's DominatorTree argument, which is the
same as the planner's DT member, and update comments that still refer to
InnerLoopVectorizer.
PR: https://github.com/llvm/llvm-project/pull/240055
[KnownFPClass][NFC] Move fma logic out of fadd_impl, and document rounding mode assumption made by fadd/fsub (#240054)
I have plans to improve deductions made by `fadd`/`fsub` and `fma`.
However, some of these deductions are only valid for `fadd`/`fsub`, so I
have moved the `fma` logic outside of `fadd_impl` and into its own
`fma_impl` function. This allows us to make improvements to `fadd/fsub`
independently of `fma`, and it also makes it easier to audit
improvements to `fma`.
I also have plans to support the rounding mode for primitive arithmetic
functions https://github.com/llvm/llvm-project/issues/228974, so I have
documented the `NearestTiesToEven` assumption that `fadd_impl` makes
when ruling out `-0.0`, allowing `fadd_impl` to be valid for all
rounding modes.
[SLP] Give failed seed a try
Previously, with the following vectorizable code:
y = x * x * x;
where IR ordered the code as:
sq = x * x;
y = sq * x;
If the seed is [sq0, y0, sq1, y1] and the cost model rejects
vectorizing sq0 and sq1, y0 will be bypassed without any retry in `I
+= ActualVF - 1`.
To fix this, we give skipped nodes a chance by using them as the root
of the tree and rebuilding it. In the retry logic, we starts from
bring the child of failure match (sq0,sq1) but uses FirstSkipped as
the filter. In here, [y0, y1] will be the new User to go
TryVectorizeWindow. If it still fails, it tried to bring its child in
as the next level try. For example, [sq0, y0, z0, sq1, y1, z1]. [y0,
y1] will brings [z0, z1] in until converge.
[SLP] Pruning when there is no Undef
By checking all (two) of the users of isGuaranteedNotToBePoison.
1. IsNotPoisonedVec: FindReusedSplat do same check as HasUndefScalars
so it never called and can safely prunning.
2. all_of(NonConstants, [=](Value *V)...: Also do the same check as
HasUndefScalars.
Nowadays, we generates very few undef value. So the prunning here
makes sense as we try to do linear check to find a possible undef
instead of calling the very expensive isGuaranteedNotToBePoison.