This is an archive of the discontinued LLVM Phabricator instance.

[EarlyCSE] Mark the condition of assume intrinsic as true
ClosedPublic

Authored by mkazantsev on Apr 25 2017, 2:05 AM.

Details

Summary

EarlyCSE should not just ignore assumes. It should use the fact that its condition is true for all dominated instructions.

Diff Detail

Repository
rL LLVM

Event Timeline

sanjoy accepted this revision.Apr 25 2017, 11:20 AM

lgtm

lib/Transforms/Scalar/EarlyCSE.cpp
638 ↗(On Diff #96525)

I think you can do:

Instruction *CondI;
if (match(Inst, m_Intrinsic<Intrinsic::assume>(m_Instruction(CondI))) &&
    SimpleValue::canHandle(CondI))
  AvailableValues.insert(CondI, ConstantInt::getTrue(BB->getContext()));
This revision is now accepted and ready to land.Apr 25 2017, 11:20 AM
dberlin added inline comments.
lib/Transforms/Scalar/EarlyCSE.cpp
638 ↗(On Diff #96525)

Can you please also just add a test that llvm.assume(false/true) is skipped?

645 ↗(On Diff #96525)

You aren't skipping it, you should say that :)

mkazantsev marked 3 inline comments as done.

Added some tests, addressed comments.

lib/Transforms/Scalar/EarlyCSE.cpp
638 ↗(On Diff #96525)

@sanjoy , no, because we need to skip assume even if its arg is not an instruction. Added test18 on that.
@dberlin , added tests 16 and 17 on that.

mkazantsev requested review of this revision.Apr 27 2017, 12:17 AM
mkazantsev edited edge metadata.
reames accepted this revision.Apr 27 2017, 6:45 PM

LGTM

I think we should constant fold the condition as well as infer it, but that can be a separate patch.

This revision is now accepted and ready to land.Apr 27 2017, 6:45 PM
This revision was automatically updated to reflect the committed changes.