This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] More unsigned binary op implied conditions
Needs RevisionPublic

Authored by caojoshua on Jun 11 2023, 12:22 AM.

Details

Summary

We add rules for sub, mul, udiv, urem, shl, and &&. We also add
strengthened rule for add to work for all Values, and not just
constants. We have to check for zeros for mul, div, and urem.

Diff Detail

Event Timeline

caojoshua created this revision.Jun 11 2023, 12:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 11 2023, 12:22 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
caojoshua requested review of this revision.Jun 11 2023, 12:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 11 2023, 12:22 AM
nikic requested changes to this revision.Jun 11 2023, 12:30 AM

I predicted this is going to happen in https://reviews.llvm.org/D149510#4315073, and now it is happening. You are reimplementing InstSimplify comparison folding in isTruePredicate().

This revision now requires changes to proceed.Jun 11 2023, 12:30 AM

I predicted this is going to happen in https://reviews.llvm.org/D149510#4315073, and now it is happening. You are reimplementing InstSimplify comparison folding in isTruePredicate().

Oops. I thought this was a draft.

I can give an attempt at using SimplifyICmpInst as you mentioned, and see how much compile time is impacted.

I predicted this is going to happen in https://reviews.llvm.org/D149510#4315073, and now it is happening. You are reimplementing InstSimplify comparison folding in isTruePredicate().

I'm not aware of where in InstSimplify this is re-implementing. simplifyICmp() and simplifyICmpOfBools() both make calls out to isTruePredicate(). Passing in the test examples to places like InstCombine or ConstraintElimination does not simplify. I don't believe existing logic to simplify these cases exists right now.

I believe that isTruePredicate() is the correct place to put this logic right now. I agree with your concerns on writing a bunch of different rules, but I don't see another way if we want to optimize these cases (maybe pick out the ones that are more useful, like subtraction).

nikic added a comment.Jun 12 2023, 3:01 AM

I predicted this is going to happen in https://reviews.llvm.org/D149510#4315073, and now it is happening. You are reimplementing InstSimplify comparison folding in isTruePredicate().

I'm not aware of where in InstSimplify this is re-implementing. simplifyICmp() and simplifyICmpOfBools() both make calls out to isTruePredicate(). Passing in the test examples to places like InstCombine or ConstraintElimination does not simplify. I don't believe existing logic to simplify these cases exists right now.

I don't follow. isTruePredicate() is a static function in ValueTracking, so how can InstSimplify call it?

You should be able to find the cases you're duplicating in simplifyICmpWithBinOpOnLHS().