This is an archive of the discontinued LLVM Phabricator instance.

[IndVarSimplify] Fix Modified status for removal of overflow intrinsics
ClosedPublic

Authored by dstenb on Aug 14 2020, 6:25 AM.

Details

Summary

When removing an overflow intrinsic the Changed status in SimplifyIndvar
was not set, leading to the IndVarSimplify pass returning an incorrect
status.

This was caught using the check introduced by D80916.

Diff Detail

Event Timeline

dstenb created this revision.Aug 14 2020, 6:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 14 2020, 6:25 AM
dstenb requested review of this revision.Aug 14 2020, 6:25 AM
bjope added a subscriber: bjope.Aug 14 2020, 10:31 AM
bjope added inline comments.
llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
480

I got a feeling that these eliminate functions return true/false depending on if any changes where made. So why aren't we setting Changed=true at the using side.

Otherwise I'd expect that also eliminateTrunc below should set Changed=true before returning true. Or it would be really hard to know what to expect from these functions if only some of them update Changed.

dstenb added inline comments.Aug 17 2020, 12:23 AM
llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
480

Yes, that is a good point.

I initially thought about modifying Changed in simplifyUsers() depending on if eliminateIVUser() returns true. However, that function may return true without actually making any changes, e.g. in the case of ICmpInst, SRem, and URem instructions. I don't really know why that is the case. Therefore, I thought that this patch could be kept simple, and just align with the current behavior.

(And yes, the trunc case probably needs to be handled also.)

uabelho added a subscriber: uabelho.Sep 1 2020, 4:21 AM

I wrote
https://bugs.llvm.org/show_bug.cgi?id=47381
about a similar problem also caused by the missing setting of Changed in SimplifyIndvar::eliminateOverflowIntrinsic.

reames accepted this revision.Sep 28 2020, 11:20 AM

LGTM for the narrow fix as written + pointing out a nearby bug.

A broader fix is worth discussing, but no reason to hold back a local fix.

llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
474

JFYI, as a separate issue, this logic shouldn't be here. We should be adding the empty extracts to the DeadInst set instead and deferring deletion.

This revision is now accepted and ready to land.Sep 28 2020, 11:20 AM
This revision was landed with ongoing or failed builds.Sep 29 2020, 4:21 AM
This revision was automatically updated to reflect the committed changes.

I added a comment about eliminateTrunc to the commit message. I'll see if I can create a reproducer for that, and if so, I'll upload a revision for that.