This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] add UGT/UGE and SGT/SGE in `isImpliedCondOperands`
ClosedPublic

Authored by floatshadow on Apr 28 2023, 11:29 PM.

Details

Diff Detail

Event Timeline

floatshadow created this revision.Apr 28 2023, 11:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 28 2023, 11:29 PM
floatshadow requested review of this revision.Apr 28 2023, 11:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 28 2023, 11:29 PM
floatshadow set the repository for this revision to rG LLVM Github Monorepo.Apr 28 2023, 11:29 PM

update test cases

floatshadow retitled this revision from [InstSimplify] add UGT and UGE case in isImpliedCondOperands to [ValueTracking] add UGT/UGE and lshr case in imply icmp.Apr 29 2023, 1:34 AM
goldstein.w.n added inline comments.
llvm/lib/Analysis/ValueTracking.cpp
8004

nit: fmt.

address comments

llvm/lib/Analysis/ValueTracking.cpp
8004

got aligned.

goldstein.w.n accepted this revision.Apr 29 2023, 12:05 PM

LGTM. I'm not a maintainer to please wait a day or so to push so other have a chance to see.

This revision is now accepted and ready to land.Apr 29 2023, 12:05 PM
floatshadow added a comment.EditedApr 29 2023, 11:03 PM

LGTM. I'm not a maintainer to please wait a day or so to push so other have a chance to see.

Thanks. I am not sure why isImpliedCondOperands handles less case only. Do we expect instcombine will canonicalize this?

LGTM. I'm not a maintainer to please wait a day or so to push so other have a chance to see.

Thanks. I am not surely why isImpliedCondOperands handles less case only. Do we expect instcombine will canonicalize this?

I'm not really sure. I think probably alot of the patterns are scattered around instcombine + instsimplify but
probably also alot of holes that just havent been filled in yet and could use patches.

Maybe @nikic knows.

ping

I have no commit access

nikic added a comment.May 3 2023, 4:06 AM

The extension to isImpliedCondOperands seems pretty reasonable to me. However, I think we should also handle the sgt/sge case at the same time, otherwise we're still going to leave this incomplete. We can test this part using variations of the existing patterns in the test, e.g. https://alive2.llvm.org/ce/z/Z8idUd.

The new check in isTruePredicate I'm somewhat skeptical about. It adds support for one special case, but there are many other cases where we could determine that the predicate is true. This is essentially what the purpose of simplifyICmpInst is, and which presumably would already handle this pattern. However, there are likely compile-time concerns with just calling into InstSimplify here.

The extension to isImpliedCondOperands seems pretty reasonable to me. However, I think we should also handle the sgt/sge case at the same time, otherwise we're still going to leave this incomplete. We can test this part using variations of the existing patterns in the test, e.g. https://alive2.llvm.org/ce/z/Z8idUd.

The new check in isTruePredicate I'm somewhat skeptical about. It adds support for one special case, but there are many other cases where we could determine that the predicate is true. This is essentially what the purpose of simplifyICmpInst is, and which presumably would already handle this pattern. However, there are likely compile-time concerns with just calling into InstSimplify here.

I'd like to split the patch into smaller pieces, and this revision for isImpliedCondOperands only.
Yes, I found that contraint elimination pass and icmp imply called by simplifyICmpInst have handle the simple case. But the former failed on the eq checks (issue 61393) and the latter only checks X + C like pattern (issue 62441)

test case for extension to isImpliedCondOperands with SGT/SGE check

floatshadow retitled this revision from [ValueTracking] add UGT/UGE and lshr case in imply icmp to [ValueTracking] add UGT/UGE and SGT/SGE in `isImpliedCondOperands`.
floatshadow edited the summary of this revision. (Show Details)

split the patch

nikic added a comment.May 3 2023, 5:15 AM

Could you please also add tests for the other variations? sge/ugt/uge?

update sge/sgt/uge/ugt case

nikic added a comment.May 3 2023, 7:04 AM

Could you please also add some negative tests, e.g. where for unsigned predicate the nuw is missing? To make sure the correct implication check is done.

nikic accepted this revision.May 3 2023, 1:09 PM

LGTM. Could you please share the Name <email> to use for the commit?

LGTM. Could you please share the Name <email> to use for the commit?

Siyuan Zhu, timeorange7071@outlook.com

This revision was landed with ongoing or failed builds.May 4 2023, 8:02 AM
This revision was automatically updated to reflect the committed changes.