[PATCH] D142689: [SCEV] Remove applyLoopGuards ExprsToRewrite

Joshua Cao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 26 22:44:26 PST 2023


caojoshua created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
caojoshua requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

ExprsToRewrite is used to expand subexpressions, but it is unnecessary
and its purpose is not obvious. I changed the Guards Visitor so that it
can expand subexpressions in a single visit traversal. I think this
makes applyLoopGuards() much easier to read.

This change is not NFC. For urem guards, we directly overwrite
RewriteMap[LHS], but for other guards we write RewriteMap[RewrittenLHS].
Fix urem guards to do the same as other guards. In other words, expand
rewrites on top of existing rewrites, rather than completely overwrite
them.

I was not able to write a testcase for this change using
print<scalar-evolution> output. Manual dbgs() for this change verifies
that urem rewrites does not overwrite other rewrites.

For example, given:

  %u = urem i32 %num, 4
  %cmp = icmp eq i32 %u, 0
  tail call void @llvm.assume(i1 %cmp)
  %cmp.1 = icmp uge i32 %num, 4
  tail call void @llvm.assume(i1 %cmp.1)
  br label %for.body

The uge was getting overwritten by the urem. This change ensures both
assumes are applied.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142689

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142689.492645.patch
Type: text/x-patch
Size: 5837 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230127/9ad94eef/attachment.bin>


More information about the llvm-commits mailing list