Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4841,7 +4841,8 @@ template <class MatchContextClass> SDValue DAGCombiner::visitMUL(SDNode *N) {
// callback to determine that sequence (similar to sqrt expansion).
unsigned MathOp = ISD::DELETED_NODE;
APInt MulC = ConstValue1.abs();
// The constant `2` should be treated as (2^0 + 1).
// Decompose 2^N ± 2^M as 2^(A+B) ± 2^B. The constant `2` should be
// treated as (2^0 + 1).
Comment thread
grodranlorth marked this conversation as resolved.
Outdated
unsigned TZeros = MulC == 2 ? 0 : MulC.countr_zero();
MulC.lshrInPlace(TZeros);
if ((MulC - 1).isPowerOf2())
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3389,6 +3389,15 @@ bool X86TargetLowering::decomposeMulByConstant(LLVMContext &Context, EVT VT,
if (!ISD::isConstantSplatVector(C.getNode(), MulC))
return false;

if (VT.isVector() && VT.getScalarSizeInBits() == 8) {
// Decompose 2^m ± 2^n as 2^(a+b) ± 2^b
APInt ShiftedMulC = MulC.abs();
unsigned TZeros = ShiftedMulC == 2 ? 0 : ShiftedMulC.countr_zero();
Comment thread
grodranlorth marked this conversation as resolved.
ShiftedMulC.lshrInPlace(TZeros);
if ((ShiftedMulC - 1).isPowerOf2() || (ShiftedMulC + 1).isPowerOf2())
return true;
}

// Find the type this will be legalized too. Otherwise we might prematurely
// convert this to shl+add/sub and then still have to type legalize those ops.
// Another choice would be to defer the decision for illegal types until
Expand Down
Loading