This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Compute exit count from overflow check expressed w/ x.with.overflow intrinsics
ClosedPublic

Authored by reames on Jan 2 2022, 11:55 AM.

Details

Summary

This ports the logic we generate in instcombine for a single use x.with.overflow check for use in SCEV's analysis. The result is that we can prove trip counts for many checks, and (through existing logic) often discharge them.

Motivation comes from compiling a simple example with -ftrapv.

Diff Detail

Event Timeline

reames created this revision.Jan 2 2022, 11:55 AM
reames requested review of this revision.Jan 2 2022, 11:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 2 2022, 11:55 AM
nikic accepted this revision.Jan 3 2022, 8:50 AM

LG with some nits

llvm/lib/Analysis/ScalarEvolution.cpp
8101

I'd write these three conditions as match(ExitCond, m_ExtractValue<1>(m_WithOverflowInst(WO)).

8111

I didn't spot where this case is tested. Can you please add one where the successors are swapped? I see some tests using xor -1, but that doesn't appear to be supported by SCEV right now.

This revision is now accepted and ready to land.Jan 3 2022, 8:50 AM
reames added inline comments.Jan 4 2022, 9:14 AM
llvm/lib/Analysis/ScalarEvolution.cpp
8101

Thanks, this is *much* cleaner.

8111

Oops, you're right. Will be covered by @sadd_symbolic_swapped once the change is pushed.

This revision was landed with ongoing or failed builds.Jan 4 2022, 9:44 AM
This revision was automatically updated to reflect the committed changes.