[llvm] r208827 - InstCombine: Optimize -x s< cst

Sean Silva chisophugis at gmail.com
Fri May 16 16:40:01 PDT 2014


Sorry for the noise. Must have been due to the recent email issues.


On Fri, May 16, 2014 at 5:32 PM, David Majnemer <david.majnemer at gmail.com>wrote:

> Yes, Nick LGTM'd this. See
> http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140512/217399.htmlfor details.
>
>
> On Fri, May 16, 2014 at 4:08 PM, Sean Silva <chisophugis at gmail.com> wrote:
>
>> Did Nick ever LGTM this? The phab revision seems to not have had any
>> movement.
>>
>> -- Sean Silva
>>
>>
>> On Wed, May 14, 2014 at 6:02 PM, David Majnemer <david.majnemer at gmail.com
>> > wrote:
>>
>>> Author: majnemer
>>> Date: Wed May 14 19:02:20 2014
>>> New Revision: 208827
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=208827&view=rev
>>> Log:
>>> InstCombine: Optimize -x s< cst
>>>
>>> Summary:
>>> This gets rid of a sub instruction by moving the negation to the
>>> constant when valid.
>>>
>>> Reviewers: nicholas
>>>
>>> Subscribers: llvm-commits
>>>
>>> Differential Revision: http://reviews.llvm.org/D3773
>>>
>>> Modified:
>>>     llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
>>>     llvm/trunk/test/Transforms/InstCombine/icmp.ll
>>>
>>> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=208827&r1=208826&r2=208827&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
>>> (original)
>>> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Wed
>>> May 14 19:02:20 2014
>>> @@ -2971,6 +2971,16 @@ Instruction *InstCombiner::visitICmpInst
>>>          BO0->hasOneUse() && BO1->hasOneUse())
>>>        return new ICmpInst(Pred, D, B);
>>>
>>> +    // icmp (0-X) < cst --> x > -cst
>>> +    if (NoOp0WrapProblem && ICmpInst::isSigned(Pred)) {
>>> +      Value *X;
>>> +      if (match(BO0, m_Neg(m_Value(X))))
>>> +        if (ConstantInt *RHSC = dyn_cast<ConstantInt>(Op1))
>>> +          if (!RHSC->isMinValue(/*isSigned=*/true))
>>> +            return new ICmpInst(I.getSwappedPredicate(), X,
>>> +                                ConstantExpr::getNeg(RHSC));
>>> +    }
>>> +
>>>      BinaryOperator *SRem = nullptr;
>>>      // icmp (srem X, Y), Y
>>>      if (BO0 && BO0->getOpcode() == Instruction::SRem &&
>>>
>>> Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=208827&r1=208826&r2=208827&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
>>> +++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Wed May 14 19:02:20
>>> 2014
>>> @@ -1356,3 +1356,12 @@ define i1 @icmp_ashr_ashr_ne(i32 %a, i32
>>>   %z = icmp ne i32 %x, %y
>>>   ret i1 %z
>>>  }
>>> +
>>> +; CHECK-LABEL: @icmp_neg_cst_slt
>>> +; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %a, 10
>>> +; CHECK-NEXT: ret i1 [[CMP]]
>>> +define i1 @icmp_neg_cst_slt(i32 %a) {
>>> +  %1 = sub nsw i32 0, %a
>>> +  %2 = icmp slt i32 %1, -10
>>> +  ret i1 %2
>>> +}
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140516/f4e737f7/attachment.html>


More information about the llvm-commits mailing list