Changes TTI function getIntImmCostInst to take an additional Instruction parameter, which enables us to be able to check it is part of a min(max())/max(min()) pattern. We can then mark the constant used as free to prevent it being hoisted so SSAT can still be generated.
Required minor changes in some non-ARM backends to allow for the optional parameter to be included.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
The TTI changes here look OK to me. I think it is probably worth trying to make the ARM check a bit more specific though. We are trying to match a SSAT, not any min/max. It's worth making sure that the subtarget will have an SSAT instruction, and that the size of the type we will be saturating to will fit into an i32.
I'm not sure about having to match a more specific min(max(..)) and max(min(..)) pattern too. That will depend on how some examples look if they only have the max, but won't produce a ssat.
Made the checks more specific to min(max()) and max(min()) patterns which should generate SSAT
Improved getIntImmCostInst so that the max(min()) case is properly handled by checking the instruction's operand is a min and a select instruction.
Thanks. Looks good.
llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp | ||
---|---|---|
42 | Can you add something about matching ssat in this comment. You could consider pulling it out into a separate function too. | |
43 | The condition might be better as ((ST->hasV6Ops() && !ST->isThumb()) || ST->isThumb2()), as there are some cpu's (like the cortex-m0) which have V6Ops but not A32 or SSat. | |
60–61 | If this checks for MinSPF == SPF_SMIN first, then in case that is false we needn't look at the minRHS. I think getUniqueInteger can just be getValue too, if we know it's a ConstantInt? |
Added new helper function isSSATMinMaxPattern which checks whether the instruction being passed in is a valid max instruction that is part of a min(max()) or max(min()) pattern. Simplified getIntImmCostInst down to make a call to this function.
Very nice, LGTM.
llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp | ||
---|---|---|
52 | This can use [&] |
Can you add something about matching ssat in this comment. You could consider pulling it out into a separate function too.