[llvm] r279568 - [InstCombine] remove icmp shr folds that are already handled by InstSimplify
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 23 15:41:59 PDT 2016
Thanks, Eli. I made a couple of follow-on cleanups before I saw your mail.
Draft posted for review - make sure the comments don't cause more confusion
than they remove. :)
https://reviews.llvm.org/D23819
On Tue, Aug 23, 2016 at 3:36 PM, Friedman, Eli <efriedma at codeaurora.org>
wrote:
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160823/a625d164/attachment.html>
More information about the llvm-commits
mailing list