This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Add folds for certain icmp + vscale combinations
AbandonedPublic

Authored by david-arm on Sep 13 2021, 8:15 AM.

Details

Summary

Consider some simple cases like this:

icmp ugt i64 %vscale, 1024
icmp ugt i64 (mul i64 %vscale, 32), 1024

where

%vscale = call i64 @llvm.vscale.i64()

We may know at compile time what the maximum value of vscale is
and therefore we may know the result of the comparison. In such cases
we can fold examples like those above away completely to return a
boolean value.

Tests added here:

Transforms/InstCombine/icmp-vscale.ll

Diff Detail

Event Timeline

david-arm created this revision.Sep 13 2021, 8:15 AM
david-arm requested review of this revision.Sep 13 2021, 8:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 13 2021, 8:15 AM

Could we add vscale to ValueTracking::computeKnownBitsFromOperator? I'm not sure it would capture all the non-power-2 cases, but it would be more general and might optimize more cases.

Could we add vscale to ValueTracking::computeKnownBitsFromOperator? I'm not sure it would capture all the non-power-2 cases, but it would be more general and might optimize more cases.

That's a nice suggestion @dmgreen I'll look into it!

david-arm added inline comments.
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
1433

Hi @dmgreen, I just realised that I can probably remove the check for m_Shl now as this should be covered by D109883

david-arm updated this revision to Diff 373583.Sep 20 2021, 7:29 AM
  • Removed folds involving shl as these now work already.
david-arm edited the summary of this revision. (Show Details)Sep 20 2021, 7:30 AM
david-arm abandoned this revision.Sep 21 2021, 5:04 AM

This patch is probably not worth it anymore, since the cases it deals with are unlikely to occur in practice.