[llvm] r279568 - [InstCombine] remove icmp shr folds that are already handled by InstSimplify
Friedman, Eli via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 23 14:36:35 PDT 2016
On 8/23/2016 2:01 PM, Sanjay Patel via llvm-commits wrote:
> Author: spatel
> Date: Tue Aug 23 16:01:35 2016
> New Revision: 279568
>
> - // If we are comparing against bits always shifted out, the
> - // comparison cannot succeed.
> - APInt Comp = CmpRHSV << ShAmtVal;
> - ConstantInt *ShiftedCmpRHS = Builder->getInt(Comp);
> - if (Shr->getOpcode() == Instruction::LShr)
> - Comp = Comp.lshr(ShAmtVal);
> - else
> - Comp = Comp.ashr(ShAmtVal);
> -
> - if (Comp != CmpRHSV) { // Comparing against a bit that we know is zero.
> - bool IsICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE;
> - Constant *Cst = Builder->getInt1(IsICMP_NE);
> - return replaceInstUsesWith(ICI, Cst);
> - }
> -
> - // Otherwise, check to see if the bits shifted out are known to be zero.
> - // If so, we can compare against the unshifted value:
> + // Check if the bits shifted out are known to be zero. If so, we can compare
> + // against the unshifted value:
It's not obvious that it's actually safe to do this... I mean, you don't
need the same optimization in both InstSimplify and Instcombine, but
"Comp != CmpRHSV" also acts as a safety check here. At the very least,
there needs to be a comment explaining why this is safe.
-Eli
> // (X & 4) >> 1 == 2 --> (X & 4) == 4.
> + ConstantInt *ShiftedCmpRHS = Builder->getInt(CmpRHSV << ShAmtVal);
> if (Shr->hasOneUse() && Shr->isExact())
> return new ICmpInst(ICI.getPredicate(), Shr->getOperand(0), ShiftedCmpRHS);
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
More information about the llvm-commits
mailing list