This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Look through zero-extends in howFarToZero
ClosedPublic

Authored by kparzysz on Jun 8 2018, 9:56 AM.

Details

Summary

An expression like (zext i2 {(trunc i32 (1 + %B) to i2),+,1}<%while.body> to i32) will become zero exactly when the nested value becomes zero in its type. Instead of converting this kind of a zero-extended value into an addrec with predicates, simply remove the zext.

This is the replacement of D47899 (the motivation is explained there).

Diff Detail

Repository
rL LLVM

Event Timeline

kparzysz created this revision.Jun 8 2018, 9:56 AM
kparzysz added inline comments.
lib/Analysis/ScalarEvolution.cpp
8268 ↗(On Diff #150532)

Accidental deletion.

Makes sense. Probably should also handle SCEVSignExtendExpr.

(Needs testcases.)

sanjoy added inline comments.Jun 8 2018, 11:34 AM
lib/Analysis/ScalarEvolution.cpp
8281 ↗(On Diff #150532)

Probably better to do V = StripInjectiveFunctions(V) where StripInjectiveFunctions strips sign and zero extends before we check if V is an add rec or not.

kparzysz updated this revision to Diff 150557.Jun 8 2018, 1:14 PM

Implemented stripInjectiveFunctions (that strips sign- and zero-extensions) and used it in howFarToZero. Added a testcase.

sanjoy accepted this revision.Jun 8 2018, 1:35 PM

lgtm

lib/Analysis/ScalarEvolution.cpp
8153 ↗(On Diff #150557)

General convention is to use S for SCEV* variables, not Val.

test/Analysis/ScalarEvolution/strip-injective-zext.ll
18 ↗(On Diff #150557)

Minor: the test can probably be simplified a little bit more:

  • Use an i64 pointer instead of the %s.0 pointer
  • Strip unnecessary function attributes like dso_local, local_unnamed_addr, TBAA etc.
This revision is now accepted and ready to land.Jun 8 2018, 1:35 PM
kparzysz marked 2 inline comments as done.Jun 8 2018, 1:42 PM
This revision was automatically updated to reflect the committed changes.