This is an archive of the discontinued LLVM Phabricator instance.

Extend switch condition in optimizeSwitchPhiConst when free
ClosedPublic

Authored by MatzeB on May 3 2022, 7:08 PM.

Details

Summary

In a case like:

switch((i32)x) { case 42: phi((i64)42, ...); }

replace (i64)42 with zext(x) when we can do so for free.

This fixes a part of https://github.com/llvm/llvm-project/issues/55153

Diff Detail

Event Timeline

MatzeB created this revision.May 3 2022, 7:08 PM
MatzeB requested review of this revision.May 3 2022, 7:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 3 2022, 7:08 PM
MatzeB updated this revision to Diff 426895.May 3 2022, 7:11 PM
MatzeB updated this revision to Diff 427098.May 4 2022, 11:47 AM
MatzeB updated this revision to Diff 427373.May 5 2022, 10:00 AM
MatzeB updated this revision to Diff 427391.May 5 2022, 10:59 AM
MatzeB updated this revision to Diff 428274.May 9 2022, 8:11 PM

Push the previous patches in this sequence, so we can get some bot and real-world testing underway before adding complexity to the transform?

spatel accepted this revision.May 17 2022, 1:07 PM

The previous patches seem to be stable now, so LGTM with a couple of minor improvements.

llvm/lib/CodeGen/CodeGenPrepare.cpp
7056

formatting: TryZext or TryZExt

7066–7069

Prefer dyn_cast to isa + cast, so something like this:

auto *PHIValue = dyn_cast<ConstantInt>(PHI.getIncomingValue(I));
if (PHIValue != CaseValue)
  if (!tryZExt || !PHIValue ||
      PHIValue->getValue() !=
          CaseValue->getValue().zext(PHIType->getIntegerBitWidth()))
    continue;
This revision is now accepted and ready to land.May 17 2022, 1:07 PM
MatzeB updated this revision to Diff 430520.May 18 2022, 3:38 PM
MatzeB marked 2 inline comments as done.
This revision was landed with ongoing or failed builds.May 18 2022, 4:25 PM
This revision was automatically updated to reflect the committed changes.