Inspired by some of the cases from D145468
Let SimplifyDemandedBits handle the narrowing of lshr to half-width if we don't require the upper bits, the narrowed shift is profitable and the zext/trunc are free.
Paths
| Differential D146121
[DAG] Move lshr narrowing from visitANDLike to SimplifyDemandedBits ClosedPublic Authored by RKSimon on Mar 15 2023, 3:10 AM.
Details Summary Inspired by some of the cases from D145468 Let SimplifyDemandedBits handle the narrowing of lshr to half-width if we don't require the upper bits, the narrowed shift is profitable and the zext/trunc are free.
Diff Detail
Unit TestsFailed Event Timeline
Comment Actions Update - I'm going to investigate splitting this between the regular SimplifyDemandedBits DAG combines and some specific narrowing in X86ISelDAGToDAG.cpp + ISel - that way we have the best chance of making use of the extensive value tracking code we already have in SelectionDAG. However, a lot of the DAG combines are already in place, we're just missing them due to poor combine ordering - so getting D127115 completed once and for all will likely help us the most, so I'm looking at the remaining regressions there first, and then will revisit this for cleanup.
RKSimon retitled this revision from [DAG] Move lshr narrowing from visitANDLike to SimplifyDemandedBits (WIP) to [DAG] Move lshr narrowing from visitANDLike to SimplifyDemandedBits.Jul 7 2023, 6:36 AM
Comment Actions
One more comment. I noticed in: D154805 that for the scalars the (shl (add x, c1), c2) is not properly folding to (add (shl x, c2), c1 << c2). This is because before reaching visitSHL (and performing the fold), the shl gets shrunk and its wrapped in an ANY_EXTEND. This patch seems like to cause similiar issues. I'm still generally infavor as we can always update the folds, but is a slight concern that we may be adding a layer of indirection that not all folds work with. Comment Actions X86 changes look good to me expect one nit.
This revision is now accepted and ready to land.Jul 17 2023, 6:13 AM This revision was landed with ongoing or failed builds.Jul 17 2023, 7:50 AM Closed by commit rGe9caa37e9c69: [DAG] Move lshr narrowing from visitANDLike to SimplifyDemandedBits (authored by RKSimon). · Explain Why This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 537747 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/test/CodeGen/AMDGPU/idot4s.ll
llvm/test/CodeGen/AMDGPU/idot4u.ll
llvm/test/CodeGen/AMDGPU/idot8s.ll
llvm/test/CodeGen/AMDGPU/idot8u.ll
llvm/test/CodeGen/AMDGPU/integer-mad-patterns.ll
llvm/test/CodeGen/AMDGPU/partial-shift-shrink.ll
llvm/test/CodeGen/AMDGPU/sdwa-peephole.ll
llvm/test/CodeGen/AMDGPU/shift-i128.ll
llvm/test/CodeGen/AMDGPU/wave32.ll
llvm/test/CodeGen/X86/2008-05-12-tailmerge-5.ll
llvm/test/CodeGen/X86/2009-05-30-ISelBug.ll
llvm/test/CodeGen/X86/3addr-or.ll
llvm/test/CodeGen/X86/and-shift.ll
llvm/test/CodeGen/X86/bswap.ll
llvm/test/CodeGen/X86/combine-bitreverse.ll
llvm/test/CodeGen/X86/const-shift-of-constmasked.ll
llvm/test/CodeGen/X86/extract-bits.ll
llvm/test/CodeGen/X86/h-register-addressing-64.ll
llvm/test/CodeGen/X86/h-registers-0.ll
llvm/test/CodeGen/X86/lzcnt-cmp.ll
llvm/test/CodeGen/X86/zext-logicop-shift-load.ll
llvm/test/CodeGen/X86/zext-lshr.ll
|
Doesn't the InDemandedMask.countLeadingZeros() >= (BitWidth / 2) check the same thing as TLO.DAG.MaskedValueIsZero(Op0, APInt::getHighBitsSet(BitWidth, BitWidth / 2)) What is the rationale for having both?