This is an archive of the discontinued LLVM Phabricator instance.

ScalarEvolution: do not set nuw when creating exprs of form <expr> + <all-ones>.
ClosedPublic

Authored by pcc on Nov 19 2015, 4:58 PM.

Details

Summary

The nuw constraint will not be satisfied unless <expr> == 0.

This bug has been around since r102234 (in 2010!), but was uncovered by
r251052, which introduced more aggressive optimization of nuw scev expressions.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc updated this revision to Diff 40720.Nov 19 2015, 4:58 PM
pcc retitled this revision from to ScalarEvolution: do not set nuw when creating exprs of form <expr> + <all-ones>..
pcc updated this object.
pcc added a reviewer: sanjoy.
pcc added subscribers: hans, llvm-commits.
hans added inline comments.Nov 19 2015, 5:05 PM
lib/Analysis/ScalarEvolution.cpp
7031 ↗(On Diff #40720)

Just to double check: this one is safe right?

pcc added inline comments.Nov 19 2015, 5:12 PM
lib/Analysis/ScalarEvolution.cpp
7031 ↗(On Diff #40720)

I believe so. In this case the nsw condition will only fail if RHS is the minimum signed value, and the if condition on line 7029 checks that the range of RHS is such that this cannot happen.

sanjoy accepted this revision.Nov 19 2015, 5:23 PM
sanjoy edited edge metadata.

LGTM, good catch!

test/Transforms/IndVarSimplify/zext-nuw.ll
1 ↗(On Diff #40720)

Minor nit: is the -o - necessary?

This revision is now accepted and ready to land.Nov 19 2015, 5:23 PM
This revision was automatically updated to reflect the committed changes.
pcc added inline comments.Nov 19 2015, 5:30 PM
test/Transforms/IndVarSimplify/zext-nuw.ll
1 ↗(On Diff #40720)

No, removed.