[GVNHoist] Replace getDefiningAccess with getClobberingMemoryAccess (#240217)
getDefiningAccess in safeToHoistLdSt returns the nearest stores if we
don't query AA result by using getClobberingMemoryAccess. This reduce
the opportunity for optimization as isLiveOnEntryDef returns false
without updating in safeToHoistLdSt.
In the example (See Closes item): after hoisting left.a and left.b,
getDefiningAccess returns `store q` before.
As a result, we replace getDefiningAccess with getClobberingMemoryAccess
and then we can safely remove ensureOptimizedUses now.
Assisted-by: Claude # Test
Closes: #221578
[Hlsl][Spirv] Don't emit global variables for structs containing just resources (#234797)
For global, non-static instances of a struct containing resources, we
end up splitting these recursively into separate global variables for
each resource, and for numeric members these go into the default
$globals cbuffer.
For this change, when there's a instance of a struct (or array of)
containing only resources, skip emitting a global variable for the
struct. Before, it would emit external linkage globals of these which
would not get removed.
based on
https://github.com/llvm/wg-hlsl/blob/main/proposals/0038-resources-in-structs.md
improves #194435
assisted by: codex
[bazel][llvm] Add SelectionDAGOptionsTableGen to CodeGen deps (#240498)
Fixes build failure introduced by commit 3e3ca055b0bb ("[SelectionDAG]
Declare command line options in TableGen (Part 1) (#240033)"), which
generated SelectionDAGOptions.inc from SelectionDAGOptions.td.
Add gentbl_cc_library target SelectionDAGOptionsTableGen and add it to
CodeGen deps.
LLM-aided
[lldb][test] Lazily generate ValueCheck error messages (#240484)
We spend a large amount of time in the test suite preparing the error
messages for failed asserts. All of this time is spent on formatting
SBValue objects that we are checking, so we can print their textual
representation in the assert error.
This patch uses the typical Python lazy string class trick to make this
evaluation lazy. This speeds up several tests by a small amount, and
some tests like `TestDataFormatterGenericDeque.py` get their runtime cut
from 30s to 7s.
[lldb] Remove unused MIPS register descriptions (#239081)
Remove the unused MIPS and MIPS64 register-info tables and Linux
register-buffer structures. Keep the numbering definitions used by the
instruction emulators.
[libc][cmake] Collapse extra blank lines in cmake_format (#240295)
Updated cmake_format.py to collapse consecutive blank lines to a single
blank line and strip leading blank lines at the start of files. Applied
the updated formatter across libc CMake files.
Assisted-by: Automated tooling, human reviewed.
krb5: Don't include libsys in LIBADD
This has the curious effect of placing libsys before libc in the link
order even though libc links against libsys. While this happens to
work currently, it is fragile and fails to link properly in some edge
cases.
Sponsored by: AFRL, DARPA
Differential Revision: https://reviews.freebsd.org/D60724
[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-
[ConstraintElim] Prove sadd/ssub.with.overflow cannot overflow from the exact sum
Decompose the operands and show that the sum lies in the range of the type. This
handles patterns like A + (B - A), as well as sums involving signed min/max
results, which are split across their respective operands using monotonicity
(for example start + smax(end - start - 1, 0) <= end).
https://alive2.llvm.org/ce/z/ze8LCk
[ConstraintElim] A signed sum of operands with opposite signs cannot wrap
If one operand is known non-negative and the other non-positive, the signed
sum is between them, so it cannot overflow.
https://alive2.llvm.org/ce/z/ZF5Yqr
.github: Update actions version to 7
version 4 raises warnings when run as the runners force it to use Node
24 instead of Node 20. version 5 defaults to Node 24, but version 7
is the current version.
Reviewed by: emaste
Pull Request: https://github.com/freebsd/freebsd-src/pull/2477
Reapply `WaveMultiPrefixCountBits` with test fix (#239503)
Reapply #238132 after revert #239439. Add `WaveMultiPrefixCountBits`
with DirectX lowering. SPIR-V calls report that the builtin is not
supported on that target.
Keep the Clang IR checks in
`clang/test/CodeGenHLSL/builtins/WaveMultiPrefixCountBits.hlsl`. Put the
DXIL checks in `llvm/test/CodeGen/DirectX/WaveMultiPrefixCountBits.ll`,
where the existing directory configuration skips them when DirectX is
not built. Cover dynamic, true, and false inputs.
The first commit restores the original change. The second commit adds
the test fix. This avoids the unconditional DirectX-only command that
was present in the Clang test.
Fixes #99211.
Assisted by: GitHub Copilot
[4 lines not shown]
[lldb][test] Remove dead Continue calls from TestTargetAPI.py (#239030)
This test launches a program that has no breakpoint, which causes the
launch to stall until the process exists. Then, we call Continue several
times with a dead process. The Continue with a exited process does
nothing right now aside from stalling for 5 seconds.
This removes the dead Continue calls that were just copy-pasted from the
other tests. This removes the 20s of waiting, and cuts the test time
from 27s to 7s.
[lldb][test] Split up LibcxxStringSimulator test [NFC] (#239017)
TestDataFormatterLibcxxStringSimulator.py is by far the slowest test in
LLDB and runs for about 90s on the bot, which more than twice as long as
the second slowest test (TestTargetAPI with 38s). There isn't anything
wrong with the test itself, and I don't see anything we can easily
optimize.
Instead, this patch splits up TestDataFormatterLibcxxStringSimulator.py
into several tests that each test just one libcxx revision. This way we
can run the different subtests in parallel, which is beneficial on
machines with many cores.
Keep the condition key when a match_any WHEN clause omits its directive
The unguarded candidate of a match_any WHEN clause keeps its condition
key when the clause has a directive, but not when it omits one. A
selector with a key is then never a strict subset of one without, so
with
```
!$omp metadirective &
!$omp& when(user={condition(a)}, &
!$omp& implementation={vendor(score(4): llvm), extension(match_any)}: &
!$omp& taskwait) &
!$omp& when(user={condition(a)}, device={kind(host)}, &
!$omp& implementation={vendor(score(3): llvm), extension(match_any)}:)
```
TASKWAIT was also selected when `a` is false. Give both unguarded
candidates the key, so the first is again a strict subset of the second
and nothing is selected when `a` is false.
[9 lines not shown]
[VPlan] Remove header masks whose tail lanes aren't used
Replace a use of header-mask && x with x if the user, transitively
through freeze, logical-and, not and mask.beforefirst(freeze ...), only
reaches masks that are and'ed with the header mask again. The header
mask is a prefix and lane i of mask.beforefirst only depends on lanes
0..i, so the lanes outside of the header mask are never used.
This avoids the i1 vp.merge that EVL tail folding needs for the inner
header mask, e.g. in the early exit mask.beforefirst(freeze(header-mask
&& c)) and in switch default edges.
[VPlan] Allow tail folding early exits with side effects
Continues the work in #179595.
This allows us to tail fold e.g. the following loop:
```c
extern char a[1024], b[1024], c[1024], y[1024];
void two_guards(void) {
for (int i = 0; i < 1000; i++) {
if (a[i] == 0)
break;
if (b[i] > 3) {
if (c[i] < 9)
y[i] = 1;
}
}
}
```
[30 lines not shown]
[VPlan] Support tail folding uncountable early exits
Enables the first step towards #179595. After #237254, the MaskedHandleExitInVectorLoop early exit style uses the CFG to handle masking for early exit loops. This allows it to compose with tail folding which is also handled via the CFG in #176143.
This allows us to tail fold the following loop:
```c
extern char x[256];
int f(char * restrict y) {
for (int i = 0; i < 256; i++) {
if (x[i] == 0)
return i;
}
return -1;
}
```
Into this on RISC-V:
[18 lines not shown]
[VPlan] Lower MaskedCond earlier in the predicator. NFC
A MaskedCond is used to logically-and some condition with the current block in mask.
It's currently lowered in convertToConcreteRecipes but we can just do it earlier in VPlanPredicator, which removes the need for the separate fold in simplifyRecipe. It also enables more logical-and simplifications earlier on.
[VPlan] Use vputils::findCanonicalIVIncrement in more places. NFC
In a future patch we want to enable more scenarios with early exits and tail folding. In these scenarios the terminator will no longer be a BranchOnCount/BranchOnCond but a BranchOnTwoConds, so a bunch of canonical IV matchers break. Use vputils::findCanonicalIVIncrement instead since it searches the users of the canonical IV instead of looking at the terminator.
[VPlan] Allow early exit loops with side effects by masking in the vector loop.
When all blocks with side effects are dominated by every early exit, we can vectorize the loop if we mask off any lanes past the exit. We can do this with control flow:
```mermaid
flowchart TD
header --> exiting
exiting -->| exit mask | sideeffects --> latch --> latch.split
exiting -->| !exit mask | latch.split
```
For every early exiting block we add a branch to the latch on `!mask.beforefirst(exitcond)`. This is implemented in UncountableExitStyle::ReadOnly which is now renamed to MaskedHandleExitInVectorLoop.
This is a complementary exit style to MaskedHandleExitInScalarLoop. If any of the side effects aren't dominated by the early exit it still falls back to the scalar loop style, which is why none of the existing early exit side effect tests changed. Masking in loop is profitable for RISC-V and I'm assuming it's also profitable for AArch64 too, but if not then we can add a TTI hook for a preferred exit style.
[VPlan] Preserve SSA in early exit loops
MaskedCond is used to logically-and the condition to early exit with the current block in-mask. However because we use it in the latch block where the condition isn't defined on all paths, we have to workaround it not being in SSA in the verifier.
This fixes this by using reconstructSSA added in #212209 to preserve SSA in both the exit conditions and live outs in the exit blocks. It also means we get the right exit condition without MaskedCond and allows us to remove the MaskedCond exceptions in the verifier. MaskedCond is still kept since a followup PR will still use it.
One subtle point is that we need to freeze any branch conditions. Any lanes after and including the early exiting lane might contain poison and we can have branches on those poison lanes that didn't we didn't previously branch on in the scalar loop.
There's no miscompile on main today because we coincidentally don't keep SSA so exit conditions are read directly without being polluted by poison stemming from a branch past the early exit. But in this PR the exit conditions are polluted and we can end up with poison in the condition operand of a select, which causes an undefined result for AnyOf even if it freezes its operand. The poison in the branch will also cause problems in future if we decide to preserve uniform control flow and emit branches instead of blends. The exit_cond_merged_after_poison_branch test illustrates this.
[VPlan] Simplify BLEND X/M, false, ..., false -> M && X
If an i1 blend has false for all but one incoming value, then we can simplify this to the one non-false value. Blends by construction never have any overlapping mask values, so we don't need to worry about the order as the masks can't "shortcut" each other.