This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] extend "simplifyUsingControlFlow" supporting zext/sext/trunc for different sizes
Needs ReviewPublic

Authored by inclyc on Feb 10 2023, 3:22 AM.

Diff Detail

Event Timeline

inclyc created this revision.Feb 10 2023, 3:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2023, 3:22 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
inclyc requested review of this revision.Feb 10 2023, 3:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2023, 3:22 AM
inclyc updated this revision to Diff 496409.Feb 10 2023, 3:38 AM
  • Update comments

ping :) @nikic can you please review this revision to make sure it is what you want in https://github.com/llvm/llvm-project/issues/54561#issuecomment-1079460876 ?

khei4 added a subscriber: khei4.EditedMar 6 2023, 7:22 PM

(I'm new to around this, so those comments are just my opinions.)

llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
1307

IMHO, duplicating SuccForValue map for each casts seems a little redundant. I like collecting incoming phi values in the front and checking correspondences to unify those maps. Then we can also early return if the values don't correspond.

1379–1381

Inverting can't be determined on these lines. If you do so, these comments look obsolete, and better to be modified

1385

IMHO, this checking, which is done when creating maps, seems a bit redundant, it's better to hold conditions in some way.

inclyc added inline comments.Mar 7 2023, 6:22 AM
llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
1307

Thanks for the feedback!

I like collecting incoming phi values in the front and checking correspondences to unify those maps.

Can you elaborate your solution? Here are my worries:

Here we are going to find a operation that maps branch condition in to corresponding phi values. Not an operation that maps phi values back to branch condition.

I think I have to left "sext"/"zext"ed values here because we must know the result of the branch condition after "s/zext". That's different from truncating from PHI values. i.e. s/zext information is not recoverable. Truncating phi values to branch condition does not imply we can z/sext the branch condition back to "phi values".

1379–1381

Nice catch! I'd like to fixup this after all "functional change" reviews.

khei4 added inline comments.Mar 9 2023, 2:10 AM
llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
1307

Sorry for my vague comments. The idea was unifying later inverting checking and these casting checking. Finding SExt or ZExt is similar to decide an inversion

I think I have to left "sext"/"zext"ed values here because we must know the result of the branch condition after "s/zext".

I just thought it'll be neat to reverse the roll between Succ/Cond and Pred/Phi. Then we don't need to hold candidate values. But I feel this might be too detailed and optional, this requires the dominant condition reversed. (I just tried to write actually, but ugly wip https://github.com/llvm/llvm-project/compare/main...khei4:llvm-project:wip/khei4-sext