This is an archive of the discontinued LLVM Phabricator instance.

[IndVarSimplify] Do not expand unsafe expressions in IndVarSimplify
AbandonedPublic

Authored by mkazantsev on Oct 24 2017, 4:50 AM.

Details

Summary

When using SCEVExpander, passes are obliged to make sure that what they request
to expand is safe in terms of expander. We are going to enforce this adding an assert
that it is safe to expand what we request.

This patch makes sure that we only expand what is safe to expand in IndVarSimplify,
in particular that we don't expand division by potential zero.

Diff Detail

Event Timeline

mkazantsev retitled this revision from [LoopUnrolling] Do not expand unsafe expressions in IndVarSimplify to [IndVarSimplify] Do not expand unsafe expressions in IndVarSimplify.Oct 24 2017, 4:56 AM
sanjoy requested changes to this revision.Oct 24 2017, 9:38 AM
sanjoy added inline comments.
lib/Transforms/Scalar/IndVarSimplify.cpp
1589

Hm, I'm not sold on this. If AR is expandable (which we know since we got it from a PHI in the IR, right?) sext(AR) and zext(AR) should also be expandable.

test/Transforms/IndVarSimplify/2017-10-24_unsafe_division.ll
39

I'm not sure if I understand this test case - if %iv.trunc is 0 then doesn't the function already divide by 0 (and thus have UB, making any transformation correct by definition)?

This revision now requires changes to proceed.Oct 24 2017, 9:38 AM
mkazantsev abandoned this revision.Oct 26 2017, 1:31 AM