This is an archive of the discontinued LLVM Phabricator instance.

Make scf.for and affine.for conditionally speculatable
ClosedPublic

Authored by sanjoy on Oct 20 2022, 1:45 PM.

Details

Summary

for (I = Start; I < End; I += 1) always terminates so mark
{scf|affine}.for as RecursivelySpeculatable when step is known to be
1.

Diff Detail

Event Timeline

sanjoy created this revision.Oct 20 2022, 1:45 PM
sanjoy requested review of this revision.Oct 20 2022, 1:45 PM
zero9178 added inline comments.Oct 20 2022, 1:56 PM
mlir/lib/Dialect/SCF/IR/SCF.cpp
1069–1070

Using matchPattern with m_Constant and friends makes the code indepdent of any specific dialects ConstantLike op

sanjoy updated this revision to Diff 469423.Oct 20 2022, 5:20 PM
  • Use m_Constant
  • Change getConstantStep() to return APInt (that's more robust)
  • Refactor one obvious place in the code to use ForOp::getConstantStep()
bondhugula added inline comments.Oct 20 2022, 8:02 PM
mlir/test/Transforms/loop-invariant-code-motion.mlir
106

Any reason this has become 20?

sanjoy added inline comments.Oct 20 2022, 8:20 PM
mlir/test/Transforms/loop-invariant-code-motion.mlir
106

Just so that I could visually distinguish between the two loops.

rengolin added inline comments.Oct 21 2022, 1:57 AM
mlir/lib/Dialect/SCF/IR/SCF.cpp
1076

Don't you also have to make sure neither the induction variable nor the range change within the loop?

This is an scf.for, the most basic loop, anything can happen inside...

sanjoy updated this revision to Diff 469779.Oct 21 2022, 2:57 PM
  • Address review
mlir/lib/Dialect/SCF/IR/SCF.cpp
1076

Don't you also have to make sure neither the induction variable nor the range change within the loop?

I used a C for loop just for illustration, scf.for has more restrictive semantics and cannot change the IV or the bounds in the loop body. I'll change it to say scf.for and affine.for to make this clear.

Friendly ping!

chelini added inline comments.Oct 28 2022, 10:27 AM
mlir/test/Transforms/loop-invariant-code-motion.mlir
200

nit: %c2 is not used here. Please remove it.

chelini accepted this revision.Oct 28 2022, 10:36 AM

Thanks to me looks good. But please have a look at the build status, as it is currently failing.

This revision is now accepted and ready to land.Oct 28 2022, 10:36 AM
sanjoy updated this revision to Diff 471603.Oct 28 2022, 11:11 AM
sanjoy marked an inline comment as done.
  • Address review

Thanks to me looks good. But please have a look at the build status, as it is currently failing.

They're passing after the rebase.

This revision was automatically updated to reflect the committed changes.