This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Codegen for pmin and pmax
ClosedPublic

Authored by tlively on Jul 22 2021, 3:56 PM.

Details

Summary

Replace the clang builtins and LLVM intrinsics for {f32x4,f64x2}.{pmin,pmax}
with standard codegen patterns. Since wasm_simd128.h uses an integer vector as
the standard single vector type, the IR for the pmin and pmax intrinsic
functions contains bitcasts that would not be there otherwise. Add extra codegen
patterns that can still select the pmin and pmax instructions in the presence of
these bitcasts.

Diff Detail

Event Timeline

tlively created this revision.Jul 22 2021, 3:56 PM
tlively requested review of this revision.Jul 22 2021, 3:56 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 22 2021, 3:56 PM
aheejin added inline comments.Jul 23 2021, 11:26 AM
llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
1141

Sorry I asked this in person yesterday, but I don't think I quiet got it; why is this only for the ordered comparison? And does pseudo-min/max mean non-NaN-propagating?

1145–1149

Is it OK to change the return type? The source pattern's return type is an int vector but the resulting instruction's type is a float vector.

tlively added inline comments.Jul 23 2021, 11:38 AM
llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
1141

pseudo-min is defined as b < a ? b : a and pseudo-max is defined as a < b ? b : a. Both of these definitions use < as the float comparison operator, which for WebAssembly means OLT.

For both pseudo-min and pseudo-max, if a or b is NaN, the comparison will be false and the result will be a. So when a is NaN but b is not, these instructions are NaN-propagating. But when b is NaN and a is not, these instructions are not NaN-propagating. In contrast, the normal min and max operations propagate NaNs in either operand position.

1145–1149

Yes, this is the final step of DAG selection and we are lowering the SDNodes to TargetSDNodes here, so typing no longer applies.

aheejin accepted this revision.Jul 23 2021, 2:29 PM

Thanks for the explanation!

This revision is now accepted and ready to land.Jul 23 2021, 2:29 PM
This revision was landed with ongoing or failed builds.Jul 23 2021, 2:49 PM
This revision was automatically updated to reflect the committed changes.