From ab973a45b9796500955202ca606cf0bed083109b Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Thu, 13 Dec 2018 12:23:32 +0000 Subject: [PATCH] [DAGCombine] Moved X86 rotate_amount % bitwidth == 0 early out to DAGCombiner Remove common code from custom lowering (code is still safe if somehow a zero value gets used). llvm-svn: 349028 --- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 7 +++++++ llvm/lib/Target/X86/X86ISelLowering.cpp | 9 +-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index d6defa5..7768d12 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -6314,6 +6314,13 @@ SDValue DAGCombiner::visitRotate(SDNode *N) { if (isNullOrNullSplat(N1)) return N0; + // fold (rot x, c) -> x iff (c % BitSize) == 0 + if (isPowerOf2_32(Bitsize) && Bitsize > 1) { + APInt ModuloMask(N1.getScalarValueSizeInBits(), Bitsize - 1); + if (DAG.MaskedValueIsZero(N1, ModuloMask)) + return N0; + } + // fold (rot x, c) -> (rot x, c % BitSize) if (ConstantSDNode *Cst = isConstOrConstSplat(N1)) { if (Cst->getAPIntValue().uge(Bitsize)) { diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 386343d..63dd829 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -24793,9 +24793,6 @@ static SDValue LowerRotate(SDValue Op, const X86Subtarget &Subtarget, if (auto *BVAmt = dyn_cast(Amt)) { if (auto *RotateConst = BVAmt->getConstantSplatNode()) { uint64_t RotateAmt = RotateConst->getAPIntValue().urem(EltSizeInBits); - if (RotateAmt == 0) - return R; - return DAG.getNode(X86ISD::VROTLI, DL, VT, R, DAG.getConstant(RotateAmt, DL, MVT::i8)); } @@ -24816,12 +24813,8 @@ static SDValue LowerRotate(SDValue Op, const X86Subtarget &Subtarget, // Rotate by an uniform constant - expand back to shifts. if (auto *BVAmt = dyn_cast(Amt)) - if (auto *RotateConst = BVAmt->getConstantSplatNode()) { - uint64_t RotateAmt = RotateConst->getAPIntValue().urem(EltSizeInBits); - if (RotateAmt == 0) - return R; + if (BVAmt->getConstantSplatNode()) return SDValue(); - } // TODO: ISD::ROT* uses modulo rotate amounts, we need to handle this. -- 2.7.4