[llvm] [InstCombine] Remove shl if we only demand known signbits of shift source (PR #79014)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 7 14:13:25 PDT 2024
================
@@ -655,25 +655,31 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
}
}
- // TODO: If we only want bits that already match the signbit then we don't
+ // We only want bits that already match the signbit then we don't
// need to shift.
+ uint64_t ShiftAmt = SA->getLimitedValue(BitWidth - 1);
+ if (DemandedMask.countr_zero() >= ShiftAmt) {
+ unsigned NumHiDemandedBits = BitWidth - DemandedMask.countr_zero();
+ unsigned SignBits =
+ ComputeNumSignBits(I->getOperand(0), Depth + 1, CxtI);
----------------
goldsteinn wrote:
Can we just check `nsw` here? We will set `nsw` if `computeNumSignBits >= ShCnt` + other conditions.
https://github.com/llvm/llvm-project/pull/79014
More information about the llvm-commits
mailing list