Commit Graph

1097 Commits

Author SHA1 Message Date
paperchalice
d1a83ff3e0 [CodeGen] Rename winehprepare -> win-eh-prepare (#75024)
Forgot to rename `winehprepare` for legacy pass when port this pass to
new passmanager.
2023-12-11 13:55:27 +08:00
paperchalice
5baf66f3c2 [CodeGen] Port WasmEHPrepare to new pass manager (#74435)
Port `WasmEHPrepare` to new pass manager, also rename `wasmehprepare` to
`wasm-eh-prepare`.
2023-12-06 11:11:00 -08:00
Nikita Popov
eecb99c5f6 [Tests] Add disjoint flag to some tests (NFC)
These tests rely on SCEV looking recognizing an "or" with no common
bits as an "add". Add the disjoint flag to relevant or instructions
in preparation for switching SCEV to use the flag instead of the
ValueTracking query. The IR with disjoint flag matches what
InstCombine would produce.
2023-12-05 14:09:36 +01:00
Nikita Popov
e4a4122eb6 [IR] Remove zext and sext constant expressions (#71040)
Remove support for zext and sext constant expressions. All places
creating them have been removed beforehand, so this just removes the
APIs and uses of these constant expressions in tests.

There is some additional cleanup that can be done on top of this, e.g.
we can remove the ZExtInst vs ZExtOperator footgun.

This is part of
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179.
2023-11-03 10:46:07 +01:00
Matt Harding
bf92eba697 Fix comment in wasm unreachable test (#70340)
Some textual editing errors got through this pull request that was
merged a few weeks ago: https://github.com/llvm/llvm-project/pull/65876

This patch clears up the unintentional duplicated line, and white-space
at the end of the lines.
2023-10-26 10:23:32 -07:00
Benjamin Kramer
858d6a15a0 [wasm] Don't crash on non-simple value types during shuffle combine
These still exist during the DAGCombine phase.
2023-10-24 12:35:43 +02:00
Ashley Nelson
47f0f8ca47 [WebAssembly] Add exp10 libcall signatures (#69661)
The llvm.exp.* family of intrinsics and their corresponding libcalls
were recently added, which means we need to know their signatures.
2023-10-20 12:15:48 -07:00
Matt Harding
bd7ca98b66 Ensure NoTrapAfterNoreturn is false for the wasm backend (#65876)
In the WebAssembly back end, the TrapUnreachable option is currently
load-bearing for correctness, inserting wasm `unreachable` instructions
where needed to create valid wasm. There is another option,
NoTrapAfterNoreturn, that removes some of those traps and causes
incorrect wasm to be emitted.

This turns off `NoTrapAfterNoreturn` for the Wasm backend and adds new   
tests.
2023-10-05 09:17:45 -07:00
Yuta Saito
da0ca5dee4 [WebAssembly] Define local sp if llvm.stacksave is used (#68133)
Usually `llvm.stacksave/stackrestore` are used together with `alloca`
but they can appear without it (e.g. `alloca` can be optimized away).
WebAssembly's function local physical user sp register, which is
referenced by `llvm.stacksave` is created while frame lowering and
replaced with virtual register.
However the sp register was not created when `llvm.stacksave` is used
without `alloca`, and it led MIR verification failure about
use-before-def of sp virtual register.

Resolves https://github.com/llvm/llvm-project/issues/62235
2023-10-03 14:51:35 -07:00
Jingu Kang
ff68e43c81 [MachineLICM] Handle Subloops
It is a re-commit from reverted commit 3454cf67bd.

Following discussion on https://reviews.llvm.org/D154205, make MachineLICM pass
handle subloops with only visiting outermost loop's blocks once.

Differential Revision: https://reviews.llvm.org/D154205
2023-09-26 14:25:11 +01:00
Nikita Popov
4491f0b969 [IR] Remove unnecessary bitcast from CreateMalloc()
This bitcast is no longer necessary with opaque pointers. This
results in some annoying variable name changes in tests.
2023-09-18 14:58:16 +02:00
Benjamin Kramer
3454cf67bd Revert "[MachineLICM] Handle Subloops"
This reverts commit 5ec9699c4d. It
accesses MI after it has been hoisted.
2023-09-15 13:20:31 +02:00
Jingu Kang
5ec9699c4d [MachineLICM] Handle Subloops
Following discussion on https://reviews.llvm.org/D154205, make MachineLICM pass
handle subloops with only visiting outermost loop's blocks once.

Differential Revision: https://reviews.llvm.org/D154205
2023-09-14 18:07:31 +01:00
Simon Pilgrim
e6b85c3027 [DAG] FoldSetCC - add missing icmp(X,undef) -> isTrueWhenEqual case (REAPPLIED)
Followup to D59363 which failed to handle the icmp(X,undef) -> isTrueWhenEqual case - similar to llvm::ConstantFoldCompareInstruction

As discussed on the review, this is affecting some previously reduced test cases, but will also prevent reductions from relying on this inconsistent behaviour in the future.

Reapplied after reversion at e1e3c75c7d with a tweak to the pseudo-probe-peep.ll test

Differential Revision: https://reviews.llvm.org/D158068
2023-09-13 12:33:39 +01:00
Simon Pilgrim
e1e3c75c7d Revert rG6c56cf71ee82ec3a28e0dfc2b751bd10c16929da "[DAG] FoldSetCC - add missing icmp(X,undef) -> isTrueWhenEqual case"
Need to address a missed test change
2023-09-13 11:27:47 +01:00
Simon Pilgrim
6c56cf71ee [DAG] FoldSetCC - add missing icmp(X,undef) -> isTrueWhenEqual case
Followup to D59363 which failed to handle the icmp(X,undef) -> isTrueWhenEqual case - similar to llvm::ConstantFoldCompareInstruction

As discussed on the review, this is affecting some previously reduced test cases, but will also prevent reductions from relying on this inconsistent behaviour in the future.

Differential Revision: https://reviews.llvm.org/D158068
2023-09-13 11:01:58 +01:00
Luke Lau
6e4860f5d0 [SDAG] Add SimplifyDemandedBits support for ISD::SPLAT_VECTOR
This improves some cases where a splat_vector uses a build_pair that can be
simplified, e.g:

(rotl x:i64, splat_vector (build_pair x1:i32, x2:i32))

rotl only demands the bottom 6 bits, so this patch allows it to simplify it to:

(rotl x:i64, splat_vector (build_pair x1:i32, undef:i32))

Which in turn improves some cases where a splat_vector_parts is lowered on
RV32.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D158839
2023-08-28 10:35:56 +01:00
Yolanda Chen
291101aa8e [WebAssembly] Optimize vector shift using a splat value from outside block
The vector shift operation in WebAssembly uses an i32 shift amount type, while
the LLVM IR requires binary operator uses the same type of operands. When the
shift amount operand is splated from a different block, the splat source will
not be exported and the vector shift will be unrolled to scalar shifts. This
patch enables the vector shift to identify the splat source value from the other
block, and generate expected WebAssembly bytecode when lowering.

Reviewed By: tlively

Differential Revision: https://reviews.llvm.org/D158399
2023-08-25 08:13:27 -07:00
Jay Foad
0da19a2be5 [PEI][WebAssembly] Switch to backwards frame index elimination
Backwards frame index elimination uses backwards register scavenging,
which is preferred because it does not rely on accurate kill flags.

Differential Revision: https://reviews.llvm.org/D156691
2023-08-03 10:21:43 +01:00
Jingu Kang
351b4c17dd Revert "[MachineLICM] Handle Subloops"
This reverts commit 50dd383d08.
2023-07-20 17:12:25 +01:00
Jingu Kang
50dd383d08 [MachineLICM] Handle Subloops
Following discussion on https://reviews.llvm.org/D154205, make MachineLICM pass
handle subloops with only visiting outmost loop's blocks once.

Differential Revision: https://reviews.llvm.org/D154205
2023-07-20 16:39:13 +01:00
Fangrui Song
94830bf56c [WebAssembly] Use SetVector to stabilize iteration order after D120365
StringMap iteration order is not guaranteed to be deterministic
(https://llvm.org/docs/ProgrammersManual.html#llvm-adt-stringmap-h).
2023-07-20 00:02:06 -07:00
Jingu Kang
62ed3ff4bb Revert "[MachineLICM] Handle Subloops"
This reverts commit 33e60484d7.
2023-07-19 10:30:50 +01:00
Jingu Kang
33e60484d7 [MachineLICM] Handle Subloops
MachineLICM pass handles inner loops only when outmost loop does not have unique
predecessor. If the loop has preheader and there is loop invariant code, the
invariant code can be hoisted to the preheader in general. This patch makes the
pass handle inner loops in general.

Differential Revision: https://reviews.llvm.org/D154205
2023-07-12 16:32:14 +01:00
Nikita Popov
edb2fc6dab [llvm] Remove explicit -opaque-pointers flag from tests (NFC)
Opaque pointers mode is enabled by default, no need to explicitly
enable it.
2023-07-12 14:35:55 +02:00
Brendan Dahl
220fe00a7c [WebAssembly] Support annotate clang attributes for marking functions.
Annotation attributes may be attached to a function to mark it with
custom data that will be contained in the final Wasm file. The
annotation causes a custom section named
"func_attr.annotate.<name>.<arg0>.<arg1>..." to be created that will
contain each function's index value that was marked with the annotation.

A new patchable relocation type for function indexes had to be created so
the custom section could be updated during linking.

Reviewed By: sbc100

Differential Revision: https://reviews.llvm.org/D150803
2023-07-11 15:17:26 -07:00
David Mo
ef7ca14fa5 [WebAssembly] Report error for inline assembly with unsupported opcodes
For inline WebAssembly, passing a numeric operand to global.get is
unsupported. This causes encodeInstruction to reach an llvm_unreachable
call, leading to undefined behaviors. This patch fixes the issue for
this invalid instruction encoding, making it report an error by adding
an MCContext field in class WebAssemblyMCCodeEmitter.

Reviewed By: sbc100, bryanpkc

Differential Revision: https://reviews.llvm.org/D154734
2023-07-11 10:36:25 -04:00
Derek Schuff
ad14659f72 [WebAssembly] Add frexp{f,l} libcall signatures
The llvm.frexp.* family of intrinsics and their corresponding libcalls were
recently added, which means we need to know their signatures.

Differential Revision: https://reviews.llvm.org/D154639
Fixed: https://github.com/llvm/llvm-project/issues/63657
2023-07-06 13:37:11 -07:00
Thomas Lively
4f065fcb57 [WebAssembly] Fix incorrect assertion in SIMD reduction codegen
The codegen routine introduced in 18077e9fd6 did not account for vectors with
more than 16 lanes. Remove the incorrect assertion and bail out of the
optimization when encountering this case. Add test cases that previously
triggered the assertion. Unfortunately, these test cases now have terrible
codegen, but that is at least better than crashing.

Fixes #63500.

Differential Revision: https://reviews.llvm.org/D154124
2023-06-30 11:30:18 -07:00
Eli Friedman
bc7f11ccb0 [SelectionDAG] Improve expansion of wide min/max
The current implementation tries to handle the high and low halves
separately, but that's less efficient in most cases; use a wide SETCC
instead.

Differential Revision: https://reviews.llvm.org/D151358
2023-06-26 10:45:41 -07:00
xortoast
bb648c9177 [WebAssembly] Add lowering for llvm.rint and llvm.roundeven
WebAssembly doesn't expose inexact exceptions, so frint can be mapped to
fnearbyint. Likewise, WebAssembly always rounds ties-to-even, so
froundeven can be mapped to fnearbyint.

Differential Revision: https://reviews.llvm.org/D153451
2023-06-23 14:07:11 -07:00
Matt Arsenault
80e2c26dfd RegisterCoalescer: Fix name of pass
I finally snapped and fixed this inconsistency.
2023-06-21 10:30:43 -04:00
Caleb Zulawski
18077e9fd6 [WebAssembly] Re-land 8392bf6000
Correctly handle single-element vectors to fix an assertion failure. Add tests
that were missing from the original commit.

Differential Revision: D151782
2023-06-09 08:42:27 -07:00
Heejin Ahn
90073e8de3 [WebAssembly] Error out on invalid personality functions
Without explicitly checking and erroring out, an invalid personality
function, which is not `__gxx_wasm_personality_v0`, caused
a segmentation fault down the line because `WasmEHFuncInfo` was not
created. This explicitly checks the validity of personality functions in
functions with EH pads and errors out explicitly with a helpful error
message. This also adds some more assertions to ensure `WasmEHFuncInfo`
is correctly created and non-null.

Invalid personality functions wouldn't be generated by our Clang, but
can be present in handwritten ll files, and more often, in files
transformed by passes like `metarenamer`, which is often used with
`bugpoint` to simplify names in `bugpoint`-reduced files.

Reviewed By: dschuff

Differential Revision: https://reviews.llvm.org/D152203
2023-06-08 16:59:49 -07:00
Thomas Lively
100c756d96 Revert "Improve WebAssembly vector bitmask, mask reduction, and extending"
This reverts commit 8392bf6000.

The commit missed some edge cases that led to crashes. Reverting to resolve
downstream breakage while a fix is pending.
2023-06-08 14:36:29 -07:00
Derek Schuff
5f6f8a8e25 [WebAssembly] Add ldexp{,f,l} libcall signatures
llvm.ldexp.* intrinsics were recently added to LLVM, which means
wasm now needs to know the signatures of the corresponding libcalls.

Differential Revision: https://reviews.llvm.org/D152385

Fixes: #63164
2023-06-07 10:45:39 -07:00
Caleb Zulawski
8392bf6000 Improve WebAssembly vector bitmask, mask reduction, and extending
This is inspired by a recently filed Rust issue noting poor codegen for vector masks (https://github.com/rust-lang/portable-simd/issues/351).

Reviewed By: tlively

Differential Revision: https://reviews.llvm.org/D151782
2023-06-07 10:20:22 -07:00
Noah Goldstein
809b1d834d [KnownBits] Return 0 for poison {s,u}div inputs
It seems consistent to always return zero for known poison rather than
varying the value. We do the same elsewhere.

Differential Revision: https://reviews.llvm.org/D150922
2023-06-06 15:14:10 -05:00
Paulo Matos
9571a28ee4 [WebAssembly] Add tests ensuring rotates persist
Due to the nature of WebAssembly, it's always better to keep
rotates instead of trying to optimize it. Commit 9485d983
disabled the generation of fsh for rotates, however these
tests ensure that future changes don't change the behaviour for
the Wasm backend that tends to have different optimization
requirements than other architectures. Also see:
https://github.com/llvm/llvm-project/issues/62703

Differential Revision: https://reviews.llvm.org/D152126
2023-06-06 07:48:35 +02:00
Craig Topper
139392c0a5 [LegalizeTypes][ARM][AArch6][RISCV][VE][WebAssembly] Add special case for smin(X, -1) and smax(X, 0) to ExpandIntRes_MINMAX.
We can compute a simpler expression for Lo for these cases. This
is an alternative for the test cases in D151180 that works for
more targets.

This is similar to some of the special cases we have for expanding
setcc operands.

Differential Revision: https://reviews.llvm.org/D151182
2023-05-23 09:19:55 -07:00
Tobias Hieta
f84bac329b [NFC][Py Reformat] Reformat lit.local.cfg python files in llvm
This is a follow-up to b71edfaa4e
since I forgot the lit.local.cfg files in that one.

Reformatting is done with `black`.

If you end up having problems merging this commit because you
have made changes to a python file, the best way to handle that
is to run git checkout --ours <yourfile> and then reformat it
with black.

If you run into any problems, post to discourse about it and
we will try to help.

RFC Thread below:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Reviewed By: barannikov88, kwk

Differential Revision: https://reviews.llvm.org/D150762
2023-05-17 17:03:15 +02:00
Tobias Hieta
b71edfaa4e [NFC][Py Reformat] Reformat python files in llvm
This is the first commit in a series that will reformat
all the python files in the LLVM repository.

Reformatting is done with `black`.

See more information here:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Reviewed By: jhenderson, JDevlieghere, MatzeB

Differential Revision: https://reviews.llvm.org/D150545
2023-05-17 10:48:52 +02:00
Thomas Lively
72a72315b0 [WebAssembly] Mark @llvm.wasm.shuffle lane indices as immediates
This intrinsic is meant to lower directly to the i8x16.shuffle instruction,
which takes its lane index arguments as immmediates. The ISel for the intrinsic
assumed that the lane index arguments were constants, so bitcode that
"incorrectly" used this intrinsic with non-immediate arguments caused an
assertion failure in the backend.

Avoid the crash by defining the lane index arguments to be immediates, matching
the underlying instruction. Update ISel accordingly. This change means that the
bitcode that previously caused a crash will now fail to validate.

Fixes #55559.

Reviewed By: dschuff

Differential Revision: https://reviews.llvm.org/D149898
2023-05-05 08:12:41 -07:00
Thomas Lively
abdb5e041c [WebAssembly] Remove incorrect result from wasm64 store_lane instructions
The wasm64 versions of the v128.storeX_lane instructions was incorrectly defined
as returning a v128 value, which resulted in spurious drop instructions being
emitted and causing validation to fail. This was not caught earlier because
wasm64 has been experimental and not well tested. Update the relevant test file
to test both wasm32 and wasm64.

Fixes #62443.

Differential Revision: https://reviews.llvm.org/D149780
2023-05-03 16:00:20 -07:00
Heejin Ahn
0e37487df8 [WebAssembly] Fix selection of global calls
When selecting calls, currently we unconditionally remove `Wrapper`s of
the call target. But we are supposed to do that only when the target is
a function, an external symbol (= library function), or an alias of a
function. Otherwise we end up directly calling globals that are not
functions.

Fixes https://github.com/llvm/llvm-project/issues/60003.

Reviewed By: tlively, HerrCai0907

Differential Revision: https://reviews.llvm.org/D147397
2023-04-05 01:42:36 -07:00
Heejin Ahn
47fc0186e6 [WebAssembly] Move call_indirect_alloca to call.ll
Not sure the distinction between `call.ll` and `call-indirect.ll`,
because `call.ll` also seems to contain many `call_indirect` tests. Also
before D147033 `call-indirect.ll` only contained a single test and it
also tests it with `obj2yaml`, so I guess that file was created for
testing functionalities for object files as well.

We can probably merge these two someday. But anyway, this moves
`call_indirect_alloca` I added in D147033 to `call.ll`, given that that
file contains more `call_indirect` tests and I'm planning to add more
`call_indirect` tests in a followup CL.

Reviewed By: tlively

Differential Revision: https://reviews.llvm.org/D147396
2023-04-05 01:41:59 -07:00
Thomas Lively
62bfb0b14c [WebAssembly] Add libcall signatures for roundeven
Since clang started emitting roundeven intrinsics in a7d6593a0a, they would
cause a crash in the WebAssembly backend because it did not know the roundeven
library function signatures. Fix the crash by adding the signatures.

Differential Revision: https://reviews.llvm.org/D147476
2023-04-04 08:32:26 -07:00
Nikita Popov
1b16c70299 [WebAssembly] Convert tests to opaque pointers (NFC) 2023-04-04 12:16:50 +02:00
Peter Rong
3b2476910b [WASM] Prevent casting undef to CosntantSDNode
WebAssembly tries to cast an `undef` to `CosntantSDNode` during `LowerAccessVectorElement`.
These operations will trigger an assertion error in cast.
To avoid this issue, we prevent casting, and abort the lowering operation.
A unit test is also included.

This patch fixes [pr61828](https://github.com/llvm/llvm-project/issues/61828)

Reviewed By: tlively

Differential Revision: https://reviews.llvm.org/D147198
2023-03-30 20:14:11 -07:00
Peter Rong
51a93828d7 [WASM] Fix legalizer for LowerBUILD_VECTOR.
Constants in BUILD_VECTOR may be down cast into a smaller value that fits LaneBits, i.e., the bit width of elements in the vector.
This cast didn't consider 2^N where it would be cast into -2^N, which still doesn't fit into LaneBits after casting.
This will cause an assertion in later legalization.

2^N should be cast into 0, and this patch reflects such behavior.
This patch also includes a test to reflect the fix.
This patch fixes [issue 61780](https://github.com/llvm/llvm-project/issues/61780)

Related patch: https://reviews.llvm.org/D108669

Reviewed By: tlively

Differential Revision: https://reviews.llvm.org/D147208
2023-03-30 19:20:04 -07:00