This is an archive of the discontinued LLVM Phabricator instance.

[SCEV][NFC] Verify IR in isLoop[Entry,Backedge]GuardedByCond
ClosedPublic

Authored by mkazantsev on Oct 5 2018, 3:22 AM.

Details

Summary

We have a lot of various bugs that are caused by misuse of SCEV (in particular in LV),
all of them can simply be described as "we ask SCEV to prove some fact on invalid IR".
Some of examples of those are PR36311, PR37221, PR39160.

The problem is that these failues manifest differently (what we saw was failure of various
asserts across SCEV, but there can also be miscompiles). This patch adds an assert into two
SCEV methods that strongly rely on correctness of the IR and are involved in known failues.
This will at least allow us to have a clear indication of what was wrong in this case.

This patch also fixes a unit test with incorrect IR that fails this verification.

Diff Detail

Event Timeline

mkazantsev created this revision.Oct 5 2018, 3:22 AM
mkazantsev updated this revision to Diff 168449.Oct 5 2018, 3:23 AM
fhahn added a comment.Oct 5 2018, 7:27 AM

verifyFunction is relatively expensive IIRC and isLoopBackedgeGuardedByCond is potentially called multiple times for the same function, so I am slightly worried about increasing the runtime too much. Maybe it would be better under EXPENSIVE_CHECKS?

sanjoy added a comment.Oct 5 2018, 9:57 AM

+1 on the general idea, though like Florian I too think this is too expensive for a normal debug build. How about putting it under a flag (putting under EXPENSIVE_CHECKS requires a recompile right?) that can even run on release builds? That flag can even be enabled by default on EXPENSIVE_CHECKS builds.

I agree with Sanjoy. Making this available under a flag would be good.

Moved under EXPENSIVE_CHECKS.

Changed to option.

Added notion of this option being slow. It can be later be turned on in EXPENSIVE_CHECKS mode along with the other two. I tried turning it on now and currently all three turned on fail 2 tests. Apparently a bug in there.

fhahn accepted this revision.Nov 7 2018, 4:27 AM

LGTM.

Added notion of this option being slow. It can be later be turned on in EXPENSIVE_CHECKS mode along with the other two. I tried turning it on now and currently all three turned on fail 2 tests. Apparently a bug in there.

If there are failing tests, could you create a ticket so we can keep track of them?

lib/Analysis/ScalarEvolution.cpp
166

Maybe change the name to something like verify-scev-ir to be more in line with the other verify flags?

This revision is now accepted and ready to land.Nov 7 2018, 4:27 AM
mkazantsev marked an inline comment as done.Nov 7 2018, 9:09 PM
This revision was automatically updated to reflect the committed changes.