This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG][RISCV][AMDGPU][ARM] Improve SimplifyDemandedBits for SHL with variable shift amount.
ClosedPublic

Authored by craig.topper on Mar 16 2022, 11:30 AM.

Details

Summary

If we have a variable shift amount and the demanded mask has leading
zeros, we can propagate those leading zeros to not demand those bits
from operand 0. This can allow zero_extend/sign_extend to become
any_extend. This pattern can occur due to C integer promotion rules.

This transform is already done by InstCombineSimplifyDemanded.cpp where
sign_extend can be turned into zero_extend for example.

Diff Detail

Event Timeline

craig.topper created this revision.Mar 16 2022, 11:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2022, 11:30 AM
craig.topper requested review of this revision.Mar 16 2022, 11:30 AM

Seems like it should get a dedicated test to stress the edge cases

RKSimon added a subscriber: foad.Jun 19 2022, 2:28 AM

Seems like it should get a dedicated test to stress the edge cases

SGTM - @foad do you have any particular concerns or tests you'd expect?

foad accepted this revision.Jun 20 2022, 1:10 AM

LGTM (modulo Matt's request for more tests). Obviously we could do the same thing for low order bits for right shifts.

This revision is now accepted and ready to land.Jun 20 2022, 1:10 AM
craig.topper planned changes to this revision.Jul 11 2022, 11:13 AM
craig.topper added inline comments.Jul 11 2022, 11:18 AM
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
1733

Need to drop poison flags here.

This revision is now accepted and ready to land.Jul 11 2022, 11:20 AM

Drop poison flags

Slightly simplify the RISCV tests.

craig.topper added inline comments.Jul 11 2022, 12:38 PM
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
1740

Having reviewed what happens on the RISCV test cases for dropping poison, I think this can be simplified both here and in ISD::ADD/SUB/MUL. I've posted D129511 for that simplification. If it's accepted I'll apply it here too.

Simplify dropping poison flags.
More directed tests.

craig.topper requested review of this revision.Jul 11 2022, 3:41 PM
spatel accepted this revision.Jul 14 2022, 2:05 PM

LGTM

This revision is now accepted and ready to land.Jul 14 2022, 2:05 PM