This is an archive of the discontinued LLVM Phabricator instance.

[SimplifyIndVar] Constant fold IV users
ClosedPublic

Authored by etherzhhb on Sep 25 2017, 9:16 PM.

Details

Summary

This patch tries to transform cases like:

for (unsigned i = 0; i < N; i += 2) {
  bool c0 = (i & 0x1) == 0;
  bool c1 = ((i + 1) & 0x1) == 1;
}

To

for (unsigned i = 0; i < N; i += 2) {
  bool c0 = true;
  bool c1 = true;
}

Diff Detail

Repository
rL LLVM

Event Timeline

etherzhhb created this revision.Sep 25 2017, 9:16 PM
sanjoy accepted this revision.Sep 25 2017, 10:05 PM

Nice!

lib/Transforms/Utils/SimplifyIndVar.cpp
547 ↗(On Diff #116642)

s/ParentLoop/L

ParentLoop would can be confused with the parent loop of the loop containing I

test/Transforms/IndVarSimplify/replace-srem-by-urem.ll
74 ↗(On Diff #116642)

Did you change this to prevent constant folding? If so, please mention that in the commit message.

This revision is now accepted and ready to land.Sep 25 2017, 10:05 PM
etherzhhb added inline comments.Sep 26 2017, 9:13 AM
test/Transforms/IndVarSimplify/replace-srem-by-urem.ll
74 ↗(On Diff #116642)

Ok, I am thinking to copy this case over to constant-fold.ll

This revision was automatically updated to reflect the committed changes.