This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Remove applyLoopGuards ExprsToRewrite
AbandonedPublic

Authored by caojoshua on Jan 26 2023, 10:44 PM.

Details

Reviewers
fhahn
nikic
Summary

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.

Diff Detail

Event Timeline

caojoshua created this revision.Jan 26 2023, 10:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2023, 10:44 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
caojoshua requested review of this revision.Jan 26 2023, 10:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2023, 10:44 PM
caojoshua added inline comments.Jan 26 2023, 10:57 PM
llvm/lib/Analysis/ScalarEvolution.cpp
15035
NOTE: this is the only non-NFC change in this patch.
caojoshua abandoned this revision.Apr 20 2023, 9:21 PM
fhahn added a comment.Jun 13 2023, 3:12 AM

Is there a reason for why this was abandoned? Just curious if this is still a worthwhile simplification

Is there a reason for why this was abandoned? Just curious if this is still a worthwhile simplification

The function got rewritten pretty dramatically and I did not want to rebase and rewrite at the time. I do think this work should still be possible.