summaryrefslogtreecommitdiff
path: root/llvm/test/CodeGen/WebAssembly
AgeCommit message (Collapse)Author
2025-11-23Revert "[RegAlloc] Fix the terminal rule check for interfere with DstReg ↵Aiden Grossman
(#168661)" This reverts commit 0859ac5866a0228f5607dd329f83f4a9622dedcc. This caused a couple test failures, likely due to a mid-air collision. Reverting for now to get the tree back to green and allow the original author to run UTC/friends and verify the output.
2025-11-23[RegAlloc] Fix the terminal rule check for interfere with DstReg (#168661)hstk30-hw
This maybe a bug which is introduced by commit 6749ae36b4a33769e7a77cf812d7cd0a908ae3b9, and has been present ever since. In this case, `OtherReg` always overlaps with `DstReg` cause they from the `Copy` all.
2025-11-20[WebAssembly] Lower ANY_EXTEND_VECTOR_INREG (#167529)Sam Parker
Treat it in the same manner of zero_extend_vector_inreg and generate an extend_low_u if possible. This is to try an prevent expensive shuffles from being generated instead. computeKnownBitsForTargetNode has also been updated to specify known zeros on extend_low_u.
2025-11-18[WebAssembly] Add patterns for extadd pairwise (#167960)Jasmine Tang
Add a few patterns for extadd pairwise.
2025-11-17[WebAssembly] Truncate extra bits of large elements in BUILD_VECTOR (#167223)Hongyu Chen
Fixes https://github.com/llvm/llvm-project/issues/165713 This patch handles out-of-bound vector elements and truncates extra bits.
2025-11-12CodeGen: Remove target hook for terminal rule (#165962)Matt Arsenault
Enables the terminal rule for remaining targets
2025-11-12[WebAssembly][FastISel] Bail out on meeting non-integer type in selectTrunc ↵Hongyu Chen
(#167165) Fixes https://github.com/llvm/llvm-project/issues/165438 With `simd128` enabled, we may meet vector type truncation in FastISel. To respect #138479, this patch merely bails out on non-integer IR types, though I prefer bailing out for all non-simple types as most targets (X86, AArch64) do.
2025-11-11[NFC][WebAssembly] Precommit test. (#167520)Sam Parker
2025-11-10[WebAssembly] Implement more of getCastInstrCost (#164612)Sam Parker
Fill out more information for sign and zero extend and add some truncate information; however, the primary change is to int/fp conversions. In particular, fp to (narrow) int appears to be relatively expensive.
2025-11-06[WebAssembly] vf32 to vi8, vi16 lowering (#164644)Sam Parker
Avoid scalarizing the conversion and use trunc_sat and narrow instead.
2025-11-05[WebAssembly] Use IRBuilder in FixFunctionBitcasts (NFC) (#164268)Kleis Auke Wolthuizen
Simplifies the code a bit.
2025-10-23[WebAssembly] [Codegen] Add pattern for relaxed min max from pmin/pmax-based ↵Jasmine Tang
patterns over v4f32 and v2f64 (#164486) Related to https://github.com/llvm/llvm-project/issues/55932
2025-10-22[WebAssembly] Fixup test after bfc322dd724735.Florian Hahn
Test update was missed in bfc322dd724735 due a codegen test running loop-vectorize directly. The loop does not get vectorized any longer.
2025-10-22[NFC][WebAssembly] FP conversion interleave tests (#164576)Sam Parker
2025-10-22[WebAssembly] [Codegen] Add pattern for relaxed min max from ↵Jasmine Tang
fminimum/fmaximum over v4f32 and v2f64 (#162948) Related to #55932
2025-10-20[WebAssembly] Avoid dot for v16i8 partial_smla (#163796)Sam Parker
The sequence is shorter, by two extend operations, if we just use extmul and extadd_pairwise.
2025-10-16[WebAssembly] [Codegen] Add patterns for relaxed dot (#163266)Jasmine Tang
The pattern I added for `relaxed dot` similar to normal dot @ https://github.com/llvm/llvm-project/pull/151775. For `relaxed dot add`, i noticed that in the proposal the portion of dot implementation is similar to `relaxed dot`, so I think we can add a pattern where after we do relaxed dot and do extadd pairwise, we can do `relaxed dot add`. One current obstacles is I don't think there is any pattern to singly create a extadd pairwise from other instructions so the `relaxed dot add` pattern would not cover a wide range of instructions. related to https://github.com/llvm/llvm-project/issues/55932
2025-10-16[WebAssembly] Partial SMLA with relaxed dot (#163529)Sam Parker
Lower v16i8 to v4i32 partial_smla to relaxed_dot_add. I'm still unsure whether we could/should take advantage of the unknown signedness of the rhs, and also lower the partial_sumla operation too.
2025-10-14[WebAssembly] Optimize lowering of constant-sized memcpy and memset (#163294)Derek Schuff
We currently emit a check that the size operand isn't zero, to avoid executing the wasm memory.copy instruction when it would trap. But this isn't necessary if the operand is a constant. Fixes #163245
2025-10-13[CodeGen] Use getObjectPtrOffset to generate loads/stores for mem intrinsics ↵Derek Schuff
(#80184) This causes address arithmetic to be generated with the 'nuw' flag, allowing WebAssembly constant offset folding. Fixes #79692
2025-10-13[WebAssembly] Add extra pattern for dot (#151775)Jasmine Tang
Fixes https://github.com/llvm/llvm-project/issues/50154
2025-10-13Wasm fmuladd relaxed (#163177)Sam Parker
Reland #161355, after fixing up the cross-projects-tests for the wasm simd intrinsics. Original commit message: Lower v4f32 and v2f64 fmuladd calls to relaxed_madd instructions. If we have FP16, then lower v8f16 fmuladds to FMA. I've introduced an ISD node for fmuladd to maintain the rounding ambiguity through legalization / combine / isel.
2025-10-13Revert "[WebAssembly] Lower fmuladd to madd and nmadd" (#163171)Sam Parker
Reverts llvm/llvm-project#161355 Looks like I've broken some intrinsic code generation.
2025-10-13[WebAssembly] Lower fmuladd to madd and nmadd (#161355)Sam Parker
Lower v4f32 and v2f64 fmuladd calls to relaxed_madd instructions. If we have FP16, then lower v8f16 fmuladds to FMA. I've introduced an ISD node for fmuladd to maintain the rounding ambiguity through legalization / combine / isel.
2025-10-08[WebAssembly] recognize saturating truncation (#155470)Folkert de Vries
fixes https://github.com/llvm/llvm-project/issues/153838 using the same approach as https://github.com/llvm/llvm-project/pull/155377 Recognize a manual saturating truncation and select the corresponding instruction. This is useful in general, but came up specifically in https://github.com/rust-lang/stdarch because it will allow us to drop more target-specific intrinsics in favor of cross-platform ones.
2025-10-07[WebAssembly] Check intrinsic argument count before Any/All combine (#162163)Derek Schuff
This code is activated on all INTRINSIC_WO_CHAIN but only handles a selection. However it was trying to read the arguments before checking which intrinsic it was handling. This fails for intrinsics that have no arguments.
2025-10-03[LLVM][CodeGen] Check Non Saturate Case in isSaturatingMinMax (#160637)Yatao Wang
Fix Issue #160611
2025-09-30[WebAssembly] Use partial_reduce_mla ISD nodes (#161184)Sam Parker
Addresssing issue #160847. Move away from combining the intrinsic call and instead lower the ISD nodes, using tablegen for pattern matching.
2025-09-25[WebAssembly] Remove FAKE_USEs before ExplicitLocals (#160768)Heejin Ahn
`FAKE_USE`s are essentially no-ops, so they have to be removed before running ExplicitLocals so that `drop`s will be correctly inserted to drop those values used by the `FAKE_USE`s. --- This is reapplication of #160228, which broke Wasm waterfall. This PR additionally prevents `FAKE_USE`s uses from being stackified. Previously, a 'def' whose first use was a `FAKE_USE` was able to be stackified as `TEE`: - Before ``` Reg = INST ... // Def FAKE_USE ..., Reg, ... // Insert INST ..., Reg, ... INST ..., Reg, ... ``` - After RegStackify ``` DefReg = INST ... // Def TeeReg, Reg = TEE ... DefReg FAKE_USE ..., TeeReg, ... // Insert INST ..., Reg, ... INST ..., Reg, ... ``` And this assumes `DefReg` and `TeeReg` are stackified. But this PR removes `FAKE_USE`s in the beginning of ExplicitLocals. And later in ExplicitLocals we have a routine to unstackify registers that have no uses left: https://github.com/llvm/llvm-project/blob/7b28fcd2b182ba2c9d2d71c386be92fc0ee3cc9d/llvm/lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp#L257-L269 (This was added in #149626. Then it didn't seem it would trigger the same assertions for `TEE`s because it was fixing the bug where a terminator was removed in CFGSort (#149097). Details here: https://github.com/llvm/llvm-project/pull/149432#issuecomment-3091444141) - After `FAKE_USE` removal and unstackification ``` DefReg = INST ... TeeReg, Reg = TEE ... DefReg INST ..., Reg, ... INST ..., Reg, ... ``` And now `TeeReg` is unstackified. This triggered the assertion here, that `TeeReg` should be stackified: https://github.com/llvm/llvm-project/blob/7b28fcd2b182ba2c9d2d71c386be92fc0ee3cc9d/llvm/lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp#L316 This prevents `FAKE_USE`s' uses from being stackified altogether, including `TEE` transformation. Even when it is not a `TEE` transformation and just a single use stackification, it does not trigger the assertion but there's no point stackifying it given that it will be deleted. --- Fixes https://github.com/emscripten-core/emscripten/issues/25301.
2025-09-24Revert "[WebAssembly] Remove FAKE_USEs before ExplicitLocals" (#160553)Derek Schuff
Reverts llvm/llvm-project#160228 See https://github.com/llvm/llvm-project/pull/160228#issuecomment-3329752471
2025-09-23[WebAssembly] Remove FAKE_USEs before ExplicitLocals (#160228)Heejin Ahn
`FAKE_USE`s are essentially no-ops, so they have to be removed before running ExplicitLocals so that `drop`s will be correctly inserted to drop those values used by the `FAKE_USE`s. Fixes https://github.com/emscripten-core/emscripten/issues/25301.
2025-09-19[WebAssembly] Require tags for Wasm EH and Wasm SJLJ to be defined ↵Sam Clegg
externally (#159143) Rather then defining these tags in each object file that requires them we can can declare them as undefined and require that they defined externally in, for example, compiler-rt or libcxxabi.
2025-09-12[WebAssembly] Support partial-reduce accumulator (#158060)Sam Parker
We currently only support partial.reduce.add in the case where we are performing a multiply-accumulate. Now add support for any partial reduction where the input is being extended, where we can take advantage of extadd_pairwise.
2025-09-10Revert "[DAGCombiner] Relax condition for extract_vector_elt combine" (#157953)Arthur Eubanks
Reverts llvm/llvm-project#157658 Causes hangs, see https://github.com/llvm/llvm-project/pull/157658#issuecomment-3276441812
2025-09-10[DAGCombiner] Relax condition for extract_vector_elt combine (#157658)ZhaoQi
Checking `isOperationLegalOrCustom` instead of `isOperationLegal` allows more optimization opportunities. In particular, if a target wants to mark `extract_vector_elt` as `Custom` rather than `Legal` in order to optimize some certain cases, this combiner would otherwise miss some improvements. Previously, using `isOperationLegalOrCustom` was avoided due to the risk of getting stuck in infinite loops (as noted in https://github.com/llvm/llvm-project/commit/61ec738b60a4fb47ec9b7195de55f1ecb5cbdb45). After testing, the issue no longer reproduces, but the coverage is limited to the regression/unit tests and the test-suite.
2025-09-10[WebAssembly] extadd_pairwise for PartialReduce (#157669)Sam Parker
Avoid using extends, and adding the high and low half and use extadd_pairwise instead.
2025-09-08[WebAssembly] Update the test for `half` (NFC) (#152832)Trevor Gross
Replace the existing `f16` test with the version that is uses for other architectures (typically as `half.ll`). This still covers the conversions from the existing test, but also adds checks for most simple ops. Additionally, rename `half-precision.ll` to `fp-intrinsics.ll` to keep the name similar to this test.
2025-09-02[WebAssembly] Guard use of getSymbolName with isSymbol (#156105)Derek Schuff
WebAssemblyRegStackfy checks for writes to the stack pointer to avoid stackifying across them, but it wasn't prepared for other global_set instructions (such as writes in addrspace 1). Fixes #156055 Thanks to @QuantumSegfault for reporting and identifying the offending code.
2025-08-27[WebAssembly] Implement getInterleavedMemoryOpCost (#146864)Sam Parker
First pass where we calculate the cost of the memory operation, as well as the shuffles required. Interleaving by a factor of two should be relatively cheap, as many ISAs have dedicated instructions to perform the (de)interleaving. Several of these permutations can be combined for an interleave stride of 4 and this is the highest stride we allow. I've costed larger vectors, and more lanes, as more expensive because not only is more work is needed but the risk of codegen going 'wrong' rises dramatically. I also filled in a bit of cost modelling for vector stores. It appears the main vector plan to avoid is an interleave factor of 4 with v16i8. I've used libyuv and ncnn for benchmarking, using V8 on AArch64, and observe geomean improvement of ~3% with some kernels improving 40-60%. I know there is still significant performance being left on the table, so this will need more development along with the rest of the cost model.
2025-08-27[WebAssembly] v8i8 mul support (#151145)Sam Parker
During DAG combine, promote the operands to v8i16 by concanting with an undef vector and then use extmul_low to perform the mul at i16. Finally, shuffle the low bytes out of the i16 elements into the result vector.
2025-08-22[WebAssembly] Add support for avgr_u in loops (#153252)Jasmine Tang
Fixes https://github.com/llvm/llvm-project/issues/150550. With the test case ``` void f(unsigned char *x, unsigned char *y, int n) { // should have been vectorized into avgr_u instead of seperated vectorized add and logical right shift for (int i = 0; i < n; i++) x[i] = (x[i] + y[i] + 1) / 2; } ``` the backend failed to recognize that this can be reduced to avgr_u since the loop vectorizer doesn't transform into the existing pattern in tablegen. This PR sets AVGCEIL_U as legal for v8i16 and v16i8 and selects it to avgr_u in the tablegen file.
2025-08-15[WebAssembly] Reapply #149461 with correct CondCode in combine of SETCC ↵Jasmine Tang
(#153703) This PR reapplies https://github.com/llvm/llvm-project/pull/149461 In the original `combineVectorSizedSetCCEquality`, the result of setcc is being negated by returning setcc with the same cond code, leading to wrong logic. For example, with ```llvm %cmp_16 = call i32 @memcmp(ptr %a, ptr %b, i32 16) %res = icmp eq i32 %cmp_16, 0 ``` the original PR producese all_true and then also compares the result equal to 0 (using the same SETEQ in the returning setcc), meaning that semantically, it effectively is calling icmp ne. Instead, the PR should have use SETNE in the returning setcc, this way, all true return 1, then it is compared again ne 0, which is equivalent to icmp eq.
2025-08-13Revert "[WebAssembly] Combine i128 to v16i8 for setcc & expand memcmp for 16 ↵Jasmine Tang
byte loads with simd128" (#153360) Reverts llvm/llvm-project#149461 The first test w/ memcmp in `test/neon/test_neon_wasm_simd.cpp` in the Emscripten test suite has failed. This PR applies a revert so I can take a closer look at it Test case link: https://github.com/emscripten-core/emscripten/blob/main/test/neon/test_neon_wasm_simd.cpp Compile option: `em++ test_neon_wasm_simd.cpp -O2 -mfpu=neon -msimd128 -o something.js` Original comment report: https://github.com/llvm/llvm-project/pull/149461#issuecomment-3181652746
2025-08-12[MIR] Remove std::variant from multiple save/restore point handling [nfc] ↵Philip Reames
(#153226) In review of bbde6b, I had originally proposed that we support the legacy text format. As review evolved, it bacame clear this had been a bad idea (too much complexity), but in order to let that patch finally move forward, I approved the change with the variant. This change undoes the variant, and updates all the tests to just use the array form.
2025-08-12[WebAssembly] Combine i128 to v16i8 for setcc & expand memcmp for 16 byte ↵Jasmine Tang
loads with simd128 (#149461) Fixes https://github.com/llvm/llvm-project/issues/149230 Previously, even with simd enabled via `-mattr=+simd128`, the compiler cannot utilize v128 to optimize loads and setcc of i128, instead legalizing it to consecutive i64s. This PR then adds support for setcc of i128 by converting them to v16i8's anytrue and alltrue; consequently, this benefits memcmp of 16 bytes or more (when simd128 is present). The check for enabling this optimization is if the comparison operand is either a load or an integer in i128, with the comparison code being either `EQ | NE`, without `NoImplicitFloat` function flag. Inspiration taken from RISCV's isel lowering.
2025-08-12[Test] Add and update tests for `lrint`/`llrint` (NFC) (#152662)Trevor Gross
Many backends are missing either all tests for lrint, or specifically those for f16, which currently crashes for `softPromoteHalf` targets. For a number of popular backends, do the following: * Ensure f16, f32, f64, and f128 are all covered * Ensure both a 32- and 64-bit target are tested, if relevant * Add `nounwind` to clean up CFI output * Add a test covering the above if one did not exist * Always specify the integer type in intrinsic calls There are quite a few FIXMEs here, especially for `f16`, but much of this will be resolved in the near future.
2025-08-08[IR] Remove size argument from lifetime intrinsics (#150248)Nikita Popov
Now that #149310 has restricted lifetime intrinsics to only work on allocas, we can also drop the explicit size argument. Instead, the size is implied by the alloca. This removes the ability to only mark a prefix of an alloca alive/dead. We never used that capability, so we should remove the need to handle that possibility everywhere (though many key places, including stack coloring, did not actually respect this).
2025-08-07[clang][WebAssembly] Support reftypes & varargs in ↵Hood Chatham
test_function_pointer_signature (#150921) I fixed support for varargs functions (previously it didn't crash but the codegen was incorrect). I added tests for structs and unions which already work. With the multivalue abi they crash in the backend, so I added a sema check that rejects structs and unions for that abi. It will also crash in the backend if passed an int128 or float128 type.
2025-07-30[WebAssembly] Add gc target feature to addBleedingEdgeFeatures (#151294)Hood Chatham
Also alphebetize feature list, add `-mgc` and `-mno-gc` flags, and add some missing feature tests. Reland of #151107. https://github.com/llvm/llvm-project/pull/150201#discussion_r2237982637
2025-07-29Revert "[WebAssembly] Add gc target feature to addBleedingEdgeFeatures" ↵ronlieb
(#151268) Reverts llvm/llvm-project#151107