This is an archive of the discontinued LLVM Phabricator instance.

[LIR] Strengthen the check for recurrence variable in popcnt/CTLZ
ClosedPublic

Authored by davide on May 22 2017, 2:35 PM.

Diff Detail

Event Timeline

davide created this revision.May 22 2017, 2:35 PM
davide retitled this revision from [LIR] Strenghen the check for recurrence variable in popcnt/CTLZ to [LIR] Strengthen the check for recurrence variable in popcnt/CTLZ.May 22 2017, 4:14 PM
evstupac edited edge metadata.May 23 2017, 12:44 PM

Thanks for catching this.
The patch looks good, just some inline comments to optimize the code.

lib/Transforms/Scalar/LoopIdiomRecognize.cpp
1042

I wonder if you need PhiX as a parameter. It looks like it is unused after the call.
Also it looks like the function does not modify anything, so you don't need references.

test/Transforms/LoopIdiom/pr33114.ll
2

I would mention that the test checks just no assert in comments.
That way we don't need all these IR output checks.

davide marked an inline comment as done.May 23 2017, 12:50 PM
davide added inline comments.
lib/Transforms/Scalar/LoopIdiomRecognize.cpp
1042

Isn't it used in recognizeAndInsertCTLZ ?

1042

Yes, I removed the refs.

evstupac added inline comments.May 23 2017, 1:38 PM
lib/Transforms/Scalar/LoopIdiomRecognize.cpp
1042

Isn't it used in recognizeAndInsertCTLZ ?

Yes. Right.
I was confused by function name "check". Maybe we could calculate PhiX before the check (outside the function)?
Or do like:

// checks that VarX and DefX create a loop recurrence and return corresponding phi node or NULL otherwise.
static PHINode *checkRecurrence(Value *VarX, Instruction *DefX, BasicBlock *LoopEntry) {
  PhiX = dyn_cast<PHINode>(VarX);
  if (PhiX && PhiX->getParent() == LoopEntry &&
      (PhiX->getOperand(0) == DefX || PhiX->getOperand(1) == DefX))
    return PhiX;
  return nullptr;
}
1143

Can we reuse the new function here for Inst and Inst->getOperand(0)?

1259

And here.

davide added inline comments.May 23 2017, 1:46 PM
lib/Transforms/Scalar/LoopIdiomRecognize.cpp
1143

This is NFC, I assume, but we're technically changing the check. If you don't mind, I would do that in a follow-up.

davide updated this revision to Diff 99983.May 23 2017, 1:56 PM
davide added inline comments.
lib/Transforms/Scalar/LoopIdiomRecognize.cpp
1042

I agree it should have a different name. I propose getRecurrenceVar

test/Transforms/LoopIdiom/pr33114.ll
2

Updated, I'll change this before committing.

davide updated this revision to Diff 99984.May 23 2017, 1:58 PM

Comments updated.

LGTM.

lib/Transforms/Scalar/LoopIdiomRecognize.cpp
1143

ok.

evstupac accepted this revision.May 23 2017, 2:39 PM
This revision is now accepted and ready to land.May 23 2017, 2:39 PM
This revision was automatically updated to reflect the committed changes.

Also, r303704 for the cleanup.