This is an archive of the discontinued LLVM Phabricator instance.

[X86] Add back _mask, _maskz, and _mask3 builtins for some 512-bit fmadd/fmsub/fmaddsub/fmsubadd builtins.
ClosedPublic

Authored by craig.topper on Jun 4 2018, 9:05 AM.

Details

Summary

We recently switch to using a selects in the intrinsics header files for FMA instructions. But the 512-bit versions support flavors with rounding mode which must be an Integer Constant Expression. This has forced those intrinsics to be implemented as macros. As it stands now the mask and mask3 intrinsics evaluate one of their macro arguments twice. If that argument itself is another intrinsic macro, we can end up over expanding macros. Or if its something we can CSE later it would show up multiple times when it shouldn't.

I tried adding extension around the macro and making it an expression statement and declaring a local variable. But whatever name you choose for the local variable can never be used as the name of an input to the macro in user code. If that happens you would end up with the same name on the LHS and RHS of an assignment after expansion. We might be safe if we use __ in front of the variable names because those names are reserved and user code shouldn't use that, but I wasn't sure I wanted to make that claim.

The other option which I've chosen here, is to add back _mask, _maskz, and _mask3 flavors of the builtin which we will expand in CGBuiltin.cpp to replicate the argument as needed and insert any fneg needed on the third operand to make a subtract. The _maskz isn't truly necessary if we have an unmasked version or if we use the masked version with a -1 mask and wrap a select around it. But I've chosen to make things more uniform.

I separated out the scalar builtin handling to avoid too many things going on in EmitX86FMAExpr. It was different enough due to the extract and insert that the minor duplication of the CreateCall was probably worth it.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Jun 4 2018, 9:06 AM
tkrupa added inline comments.Jun 5 2018, 3:52 AM
lib/Sema/SemaChecking.cpp
2388 ↗(On Diff #149782)

vfmsubps512_mask3, vfmsubpd512_mask3, vfmsubaddps512_mask3 and vfmsubaddpd512_mask3 are missing.

Add subtract builtins to SemaChecking.cpp

tkrupa accepted this revision.Jun 6 2018, 10:38 AM

LGTM

This revision is now accepted and ready to land.Jun 6 2018, 10:38 AM
This revision was automatically updated to reflect the committed changes.