Page MenuHomePhabricator

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

Authored by tlively on Jul 10 2020, 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.Jul 10 2020, 6:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 10 2020, 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.Jul 12 2020, 11:12 AM
  • Remove superfluous parentheses
tlively marked an inline comment as done.Jul 12 2020, 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.Jul 14 2020, 2:50 PM
tlively planned changes to this revision.Jul 21 2020, 2:10 PM
david-arm resigned from this revision.Feb 9 2021, 6:48 AM
RKSimon added inline comments.Feb 9 2021, 7:47 AM
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
2316

I don't think you need the fall through

case ISD::ABS:
  return isSplatValue(V.getOperand(0), DemandedElts, UndefElts);

@tlively Not sure what plan you have for this patch, but I've created D98778 that handles the generic ISD::ABS splat handling in SelectionDAG::isSplatValue

@tlively Not sure what plan you have for this patch, but I've created D98778 that handles the generic ISD::ABS splat handling in SelectionDAG::isSplatValue

The generic ISD::ABS splat handling has landed - it could be that we can generically fold binop(splat(),splat()) -> splat(binop()) as well

Thanks for working on this @RKSimon! FWIW, I have no problem tossing out or overhauling these patches if related work lands upstream, so please don't hesitate to make them redundant.