Page MenuHomePhabricator

[SelectionDAG][WebAssembly] Recognize splat value ABS operations
Changes PlannedPublic

Authored by tlively on Fri, Jul 10, 6:46 PM.

Details

Summary

This patch gives SelectionDAG::isSplatValue the ability to look
through ABS nodes, which allows the combine introduced in D83602 to
scalarize ABS operations when only a single lane is needed.

WebAssembly does not support ABS natively as a scalar operation, but
we still want it to be scalarized and expanded, so this patch also
adds a custom combine in the WebAssembly backend that scalarizes ABS
specifically when it is a splat and only one lane is needed. This is
useful when scalarizing WebAssembly shift values, which often contain
ABS operations in Halide output.

Depends on D83602.

Diff Detail

Unit TestsFailed

TimeTest
200 mswindows > LLVM.Transforms/LowerMatrixIntrinsics::Unknown Unit Message ("")
Script: -- : 'RUN: at line 5'; c:\ws\w5\llvm-project\premerge-checks\build\bin\opt.exe -lower-matrix-intrinsics -pass-remarks-output=C:\ws\w5\llvm-project\premerge-checks\build\test\Transforms\LowerMatrixIntrinsics\Output\remarks-shared-subtrees.ll.tmp -pass-remarks=lower-matrix-intrinsics -mtriple=arm64-apple-iphoneos C:\ws\w5\llvm-project\premerge-checks\llvm\test\Transforms\LowerMatrixIntrinsics\remarks-shared-subtrees.ll 2>&1 -disable-output | c:\ws\w5\llvm-project\premerge-checks\build\bin\filecheck.exe --check-prefix=STDERR C:\ws\w5\llvm-project\premerge-checks\llvm\test\Transforms\LowerMatrixIntrinsics\remarks-shared-subtrees.ll
170 mswindows > LLVM.Transforms/LowerMatrixIntrinsics::Unknown Unit Message ("")
Script: -- : 'RUN: at line 1'; c:\ws\w5\llvm-project\premerge-checks\build\bin\opt.exe -lower-matrix-intrinsics -S < C:\ws\w5\llvm-project\premerge-checks\llvm\test\Transforms\LowerMatrixIntrinsics\store-align-volatile.ll | c:\ws\w5\llvm-project\premerge-checks\build\bin\filecheck.exe C:\ws\w5\llvm-project\premerge-checks\llvm\test\Transforms\LowerMatrixIntrinsics\store-align-volatile.ll
140 mswindows > LLVM.Transforms/LowerMatrixIntrinsics::Unknown Unit Message ("")
Script: -- : 'RUN: at line 2'; c:\ws\w5\llvm-project\premerge-checks\build\bin\opt.exe -lower-matrix-intrinsics -S < C:\ws\w5\llvm-project\premerge-checks\llvm\test\Transforms\LowerMatrixIntrinsics\strided-store-double.ll | c:\ws\w5\llvm-project\premerge-checks\build\bin\filecheck.exe C:\ws\w5\llvm-project\premerge-checks\llvm\test\Transforms\LowerMatrixIntrinsics\strided-store-double.ll
190 mswindows > LLVM.Transforms/LowerMatrixIntrinsics::Unknown Unit Message ("")
Script: -- : 'RUN: at line 2'; c:\ws\w5\llvm-project\premerge-checks\build\bin\opt.exe -lower-matrix-intrinsics -S < C:\ws\w5\llvm-project\premerge-checks\llvm\test\Transforms\LowerMatrixIntrinsics\strided-store-float.ll | c:\ws\w5\llvm-project\premerge-checks\build\bin\filecheck.exe C:\ws\w5\llvm-project\premerge-checks\llvm\test\Transforms\LowerMatrixIntrinsics\strided-store-float.ll
140 mswindows > LLVM.Transforms/LowerMatrixIntrinsics::Unknown Unit Message ("")
Script: -- : 'RUN: at line 2'; c:\ws\w5\llvm-project\premerge-checks\build\bin\opt.exe -lower-matrix-intrinsics -S < C:\ws\w5\llvm-project\premerge-checks\llvm\test\Transforms\LowerMatrixIntrinsics\strided-store-i32.ll | c:\ws\w5\llvm-project\premerge-checks\build\bin\filecheck.exe C:\ws\w5\llvm-project\premerge-checks\llvm\test\Transforms\LowerMatrixIntrinsics\strided-store-i32.ll

Event Timeline

tlively created this revision.Fri, Jul 10, 6:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptFri, Jul 10, 6:46 PM

one minor in SelectionDAG - but a wasm dev needs to looks at the target code

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
2317

Unnecessary braces around the if()

And if you move the getOperand(0) inside the isSplatValue() call then the other braces can go as well.

tlively updated this revision to Diff 277300.Sun, Jul 12, 11:12 AM
  • Remove superfluous parentheses
tlively marked an inline comment as done.Sun, Jul 12, 11:21 AM

Wouldn't we want to add ISD::ABS to scalarizeSplatValue method in DAGCombiner.cpp too? WebAssembly wouldn't benefit from it, but it can benefit other targets that have a scalar abs instruction, and it is also consistent.

llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
1749

Why is this?

1758

Does this function run before DAGCombiner::visitEXTRACT_VECTOR_ELT or after it? Or does this replace it? If this runs once before or after it, we wouldn't be able to optimize patterns that mixes abs with add or sub, such as abs(add(abs(v1) + abs(v2))), right?

srj added a subscriber: srj.Tue, Jul 14, 2:50 PM
tlively planned changes to this revision.Tue, Jul 21, 2:10 PM