This is an archive of the discontinued LLVM Phabricator instance.

Fix llc crash processing S/UREM for -Oz builds caused by rL250825.
ClosedPublic

Authored by srking on Oct 23 2015, 5:42 PM.

Details

Reviewers
rengolin
tyomitch
Summary

When taking the remainder of a value divided by a constant, visitREM() attempts to convert the REM to a longer but faster sequence of instructions. This conversion calls combine() on a speculative DIV instruction. Commit rL250825 may cause this combine() to return a DIVREM, corrupting nearby nodes. Flow eventually hits unreachable().

This patch adds a test case and a check to prevent visitREM() from trying to convert the REM instruction in cases where a DIVREM is possible.

Diff Detail

Event Timeline

srking updated this revision to Diff 38285.Oct 23 2015, 5:42 PM
srking retitled this revision from to Fix llc crash processing S/UREM for -Oz builds caused by rL250825..
srking updated this object.
srking added reviewers: tyomitch, rengolin.
srking set the repository for this revision to rL LLVM.
srking added a subscriber: llvm-commits.
arsenm added a subscriber: arsenm.Oct 23 2015, 5:52 PM
arsenm added inline comments.
test/CodeGen/Generic/urem_crash.ll
1 ↗(On Diff #38285)

This definitely needs to check something and should not be under CodeGen/Generic

srking added inline comments.Oct 23 2015, 6:58 PM
test/CodeGen/Generic/urem_crash.ll
1 ↗(On Diff #38285)

Where should the test live?
The simple no-check style was keeping with another "crash" test I used for reference.

arsenm added inline comments.Oct 23 2015, 7:04 PM
test/CodeGen/Generic/urem_crash.ll
1 ↗(On Diff #38285)

There should probably be a test for a target with and without isIntDivCheap.

srking added inline comments.Oct 23 2015, 7:24 PM
test/CodeGen/Generic/urem_crash.ll
1 ↗(On Diff #38285)

Sounds good. x86 would work. I'll update patch.

srking updated this revision to Diff 38430.Oct 26 2015, 10:19 AM
srking removed rL LLVM as the repository for this revision.

Moved test to X86 directory and added new test functions without minsize attribute. X86 is a better home for the test since X86 returns different values for isIntDivCheap() depending on the minsize attribute.
Verified the test catches the crash bug when the s/urem fix is not in place.
Verified all tests pass with the fix.

By design, the test does not care how rem and div are eventually lowered, only that lowering does not cause node corruption.

tyomitch added inline comments.Oct 26 2015, 1:10 PM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
2332

I don't understand this comment. In particular, the code following the comment doesn't check for isIntDivCheap() before returning DIVREM. Is this intended as a FIXME: ?

srking added inline comments.Oct 26 2015, 2:09 PM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
2332

This comment is a warning, not a FIXME. This patch depends on the *current* way isIntDivCheap() checking happens in visitDIV() to prevent visitDIV() from returning a DIVREM when the caller, visitREM() in this case, can't handle such transformation. The nature and reason for this dependency is the brief text of the comment.

srking updated this revision to Diff 38465.Oct 26 2015, 2:50 PM

Improved comment and added check in visitSDIV and visitUDIV in response to feedback from Artyom Skrobov.

srking marked 2 inline comments as done.Oct 26 2015, 2:54 PM
tyomitch accepted this revision.Oct 26 2015, 3:06 PM
tyomitch edited edge metadata.

Thanks! The new comments are much more clear.

This revision is now accepted and ready to land.Oct 26 2015, 3:06 PM

Commit r251373.

tyomitch closed this revision.Nov 25 2015, 5:59 AM