This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] Fix (shl (ctlz x) n) for non-power-of-two Data
ClosedPublic

Authored by lenary on Apr 4 2023, 3:47 AM.

Details

Summary

This DAGCombine is not valid for some combinations of the known bits
of x and non-power-of-two widths of x. As shown in the bug:

  • The bitwidth of x is 35 (n=5)
  • The unknown bits of x is only the least significant bit
  • This gives the result of the ctlz two possible values: 34 or 35, both of which will give 1 when left-shifted 5 bits.
  • So the eor x, 1 that this optimisation would give is not correct.

A similar instcombine optimisation is only applied when the width of x is
a power-of-two. GlobalISel does not have this bug, as shown by the testcase.

Fixes #61549

Diff Detail

Event Timeline

lenary created this revision.Apr 4 2023, 3:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2023, 3:47 AM
lenary requested review of this revision.Apr 4 2023, 3:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2023, 3:47 AM
RKSimon accepted this revision.Apr 4 2023, 4:09 AM

LGTM

This revision is now accepted and ready to land.Apr 4 2023, 4:09 AM
lenary updated this revision to Diff 511050.Apr 5 2023, 4:39 AM
lenary edited the summary of this revision. (Show Details)
This revision was landed with ongoing or failed builds.Apr 12 2023, 9:39 AM
This revision was automatically updated to reflect the committed changes.