This is an archive of the discontinued LLVM Phabricator instance.

Fix for lost FastMathFlags in SLPVectorizer
ClosedPublic

Authored by v_klochkov on Nov 11 2016, 3:09 AM.

Details

Summary

Hello,

Please review the fix for SLPVectorizer that lost FastMathFlags in FCmp operation.

Initially this fix was proposed together with few other similar fixes
(https://reviews.llvm.org/D26436),
but since then the fix has been re-worked and some reviewers recommendations to have
separate code-reviews for each of the fixed components were taken into account.

Some explanations for this fix:

  1. The call of the method propagateIRFlags() is performed not only for FCmp. It is called for ICmp as well. It is done the same way as it is done for binary operations (i.e. the method is called even for int ADD). I think this is right approach and the method propagateIRFlags() should decide what flags and for what operations it propagates.
  1. The fix replaces the casts to <BinaryOperator> with casts to <Instruction> inside the method propagateIRFlags(). The whole work done in this method is done with help of Instruction::andIRFlags(). In my opinion, the AND'able flags used in the set of original/scalar operations should all be AND'ed. Please fix me if this is wrong or too risky.

    The alternative was to have duplicated code due to not quite clear reasons, i.e.: if (auto *VecOp = dyn_cast<BinaryOperator>(I)) { <9 lines of code here> } else if (auto *VecOp = dyn_cast<CmpInst>(I)) { <exactly the same/similar 9 lines of code here> }

The fix includes 2 new test cases inside an existing LIT test.
Also, all other LIT tests successfully passed.

Thank you,
Vyacheslav Klochkov

Diff Detail

Repository
rL LLVM

Event Timeline

v_klochkov updated this revision to Diff 77605.Nov 11 2016, 3:09 AM
v_klochkov retitled this revision from to Fix for lost FastMathFlags in SLPVectorizer.
v_klochkov updated this object.
v_klochkov added a subscriber: llvm-commits.
mzolotukhin accepted this revision.Nov 11 2016, 10:25 AM
mzolotukhin edited edge metadata.

LGTM! I wonder if there are other types of instructions that can have flags (except BinaryOperation and CmpInstruction), which we need to check as well.

Michael

llvm/test/Transforms/SLPVectorizer/X86/propagate_ir_flags.ll
351 ↗(On Diff #77605)

Can we put that in the bottom of the file?

This revision is now accepted and ready to land.Nov 11 2016, 10:25 AM
This revision was automatically updated to reflect the committed changes.

`Thank you Michael,

I am not sure about what SLPVectorizer does for calls..
If it can replace a series of scalar calls (probably intrinsic calls) with 1 call returning FP-vector,
then it may want to propagate FAST flags.

For example I can see fast flags in such LLVM IR:

define double @_Z3foov() #0 {
entry:
  %call = call fast double @_Z3barv()
  ret double %call
}

`

llvm/test/Transforms/SLPVectorizer/X86/propagate_ir_flags.ll
351 ↗(On Diff #77605)

Ok, I moved it to the end of the file.

Hi Vyacheslav,

Yes, SLP vectorizer does work with calls (see test/Transforms/SLPVectorizer/X86/intrinsic.ll), and I guess we're currently dropping flags there as well. Do you mind putting a TODO there/fixing it/filing a bug?

Thanks,
Michael

`Ok, done. Similar fix for intrinsic calls is submitted here: https://reviews.llvm.org/D26575

Thank you,
Vyacheslav Klochkov
`