This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Fix div handling
ClosedPublic

Authored by skatkov on May 31 2018, 1:44 AM.

Details

Summary

When we optimize select basing on fact that div by 0 is undef
we should not traverse the instruction which are not guaranteed to
transfer execution to next instruction. Guard intrinsic is an example.

Diff Detail

Repository
rL LLVM

Event Timeline

skatkov created this revision.May 31 2018, 1:44 AM
spatel added inline comments.May 31 2018, 6:50 AM
test/Transforms/InstCombine/sdiv-guard.ll
1 ↗(On Diff #149247)

This test already passes without the patch. Please create a test that shows the diff and use utils/update_test_checks.py to generate checks for it.

Also, we shouldn't need -inline to show a failure in instcombine.

skatkov updated this revision to Diff 149388.May 31 2018, 6:13 PM

Please take a look.

skatkov added inline comments.May 31 2018, 6:15 PM
test/Transforms/InstCombine/sdiv-guard.ll
1 ↗(On Diff #149247)

Test actually shows the diff. Without this patch it will transform guard condition to %X != 0 which is incorrect because if X is not 0 and flag is false gaurd should be triggered.

spatel accepted this revision.Jun 1 2018, 7:48 AM

LGTM - see inline comments.

lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
586 ↗(On Diff #149388)

Typo:
"If we found an instruction that we can't assume will return..."

test/Transforms/InstCombine/sdiv-guard.ll
1 ↗(On Diff #149247)

Ah, the assertions were just not strong enough then. I committed the baseline test here:
rL333756

Please remove the 'FIXME' and update/rebase the patch.

This revision is now accepted and ready to land.Jun 1 2018, 7:48 AM
This revision was automatically updated to reflect the committed changes.