This is an archive of the discontinued LLVM Phabricator instance.

[CVP] Convert an AShr to a LShr if both operands are known to be nonnegative.
ClosedPublic

Authored by mcrosier on Sep 30 2016, 12:37 PM.

Details

Summary

An arithmetic shift can be safely changed to a logical shift if the first operand is known positive. This allows ComputeKnownBits (and similar analysis) to determine the sign bit of the shifted value. In turn this allows InstCombine to canonicalize a signed comparison (a > 0) into an equality check (a != 0).

This fixes PR30577 and is the same approach taken in r263406.

Chad

Diff Detail

Repository
rL LLVM

Event Timeline

mcrosier updated this revision to Diff 73115.Sep 30 2016, 12:37 PM
mcrosier retitled this revision from to [CVP] Convert an AShr to a LShr if both operands are known to be nonnegative..
mcrosier updated this object.
mcrosier added reviewers: reames, bkramer, sanjoy.
mcrosier added subscribers: llvm-commits, haicheng.

Whether the RHS is positive doesn't matter. (If it were negative, the result of the shift would be undef anyway.)

mcrosier updated this revision to Diff 73221.Oct 2 2016, 3:03 PM
mcrosier updated this object.
mcrosier added a reviewer: efriedma.
mcrosier removed a subscriber: efriedma.

Address Eli's comment:
-Only check the first operand to ensure it is positive.

haicheng accepted this revision.Oct 7 2016, 2:34 PM
haicheng added a reviewer: haicheng.

LGTM

This revision is now accepted and ready to land.Oct 7 2016, 2:34 PM
This revision was automatically updated to reflect the committed changes.