This is an archive of the discontinued LLVM Phabricator instance.

[JumpThreading] Perform phi-translation in SimplifyPartiallyRedundantLoad.
ClosedPublic

Authored by trentxintong on Mar 2 2017, 10:26 AM.

Details

Summary

In case we are loading on a phi-load in SimplifyPartiallyRedundantLoad.
Try to phi translate it into incoming values in the predecessors before
we search for available loads.

This needs https://reviews.llvm.org/D30524

Event Timeline

trentxintong created this revision.Mar 2 2017, 10:26 AM

Update test.

junbuml added a subscriber: junbuml.

We had some discussion about improving this function in D30352. Based on that I added Renato and Daniel as reviewer.

lib/Transforms/Scalar/JumpThreading.cpp
1006

Maybe LI->isUnordered() ?

Address junbuml's comment.

lib/Transforms/Scalar/JumpThreading.cpp
1006

Good catch.

trentxintong edited the summary of this revision. (Show Details)Mar 15 2017, 2:52 PM
dberlin added inline comments.Mar 15 2017, 3:29 PM
lib/Transforms/Scalar/JumpThreading.cpp
1010

Value actually has a doPhiTranslation you can use here.

dberlin accepted this revision.Mar 15 2017, 3:30 PM

LGTM once using DoPhiTranslation.

This revision is now accepted and ready to land.Mar 15 2017, 3:30 PM

Address dberlin's comment.

@dberlin can you please also take a look at https://reviews.llvm.org/D30524 ? Its needed for this patch. Thanks!

dberlin added inline comments.Mar 15 2017, 4:10 PM
lib/Transforms/Scalar/JumpThreading.cpp
948

This logic looks overly complex.

Isn't this all simply

TranslateableLoaddedPhiPtr = LoadedPtr->doPhiTranslation(LoadBB, PredBB)

here, and then

if (TranslateableLoadedPhiPtr == LoadedPtr)
    if (Instruction *PtrOp = dyn_cast<Instruction>(LoadedPtr))
    return false

(IE what it was before).

1012

And here, translateableloadedphiptr will already be LI->getOperand(0) (which is the pointer operand)
or LI->getPointerOperand (if the translation fails)

trentxintong added inline comments.Mar 15 2017, 4:23 PM
lib/Transforms/Scalar/JumpThreading.cpp
948

Do not we need the PredBB then ? we are not iterating over the predecessors here. Otherwise, I think doPhiTranslation would be a perfect fit for this.

dberlin added inline comments.Mar 15 2017, 5:38 PM
lib/Transforms/Scalar/JumpThreading.cpp
948

good point, missed that. I would still simplify the logic

I would just define a helper:

static bool isOpDefinedInBlock(Value *Op, BasicBlock *BB)
{
  if (Instruction *OpInst = dyn_cast<Instruction>(Op))
     if (OpInst->getParent() == BB)
       return true;
  return false;
}

Then here
if (opDefinedByBlock(LoadedPtr, LoadBB) && !isa<PHINode>(LoadedPtr))

return false;

and below, just always phi translate (phi translate returns either the original pointer, or the phi translated version, it never returns null)

Address dberlin's comments

@dberlin does this look good to you ? Thanks.

I already accepted it, so i can't accept it again :)
But LGTM.
Thank you for working through this :P

can you please also take a look at https://reviews.llvm.org/D30524. Its a preparation patch for this patch.

This revision was automatically updated to reflect the committed changes.