This is an archive of the discontinued LLVM Phabricator instance.

[IndVars] Drop "exact" flag from lshr and udiv when substituting their args
ClosedPublic

Authored by mkazantsev on Oct 9 2018, 11:55 PM.

Details

Summary

There is a transform that may replace lshr (x+1), 1 with lshr x, 1 in case
if it can prove that the result will be the same. However the initial instruction
might have an exact flag set, and it now should be dropped unless we prove
that it may hold. Incorrectly set exact attribute may then produce poison.

Diff Detail

Repository
rL LLVM

Event Timeline

mkazantsev created this revision.Oct 9 2018, 11:55 PM
mkazantsev edited the summary of this revision. (Show Details)Oct 9 2018, 11:58 PM
sanjoy accepted this revision.Oct 10 2018, 11:24 AM

lgtm

lib/Transforms/Utils/SimplifyIndVar.cpp
147 ↗(On Diff #168941)

I'd give this a less generic name, like IsTransformedUDivExact or something like that.

test/Transforms/IndVarSimplify/drop-exact.ll
8 ↗(On Diff #168941)

Are there existing tests demonstrating that we do keep exact when legal? If not, would be nice to add one.

This revision is now accepted and ready to land.Oct 10 2018, 11:24 AM
mkazantsev added inline comments.Oct 11 2018, 12:09 AM
test/Transforms/IndVarSimplify/drop-exact.ll
8 ↗(On Diff #168941)

I tried playing with that, and I noticed that cases like %tmp21 = add nsw i32 %tmp17, 0 (for which that would have been legal to keep it) get optimized away earlier by other parts of IndVars, so this instruction doesn't live long enough. I will study whether or not it is possible to come here with something like this at all, and if not, I will just remove the check and drop exact unconditionally.

mkazantsev marked an inline comment as done.Oct 11 2018, 12:18 AM
This revision was automatically updated to reflect the committed changes.