[llvm] r288833 - [InstSimplify] add folds for or-of-icmps with same operands

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 6 14:22:43 PST 2016


Updated with:
https://reviews.llvm.org/rL288855

Thanks for reviewing the patch!

On Tue, Dec 6, 2016 at 2:42 PM, Sanjay Patel <spatel at rotateright.com> wrote:

> Ah, I didn't think of the swapOperands() as a mutation, but of course
> you're right. I don't see any precedent for that, so I suppose it's safer
> to just create some temps with the swapped values.
>
> On Tue, Dec 6, 2016 at 2:18 PM, Friedman, Eli <efriedma at codeaurora.org>
> wrote:
>
>> On 12/6/2016 10:09 AM, Sanjay Patel via llvm-commits wrote:
>>
>>> Author: spatel
>>> Date: Tue Dec  6 12:09:37 2016
>>> New Revision: 288833
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=288833&view=rev
>>> Log:
>>> [InstSimplify] add folds for or-of-icmps with same operands
>>>
>>> All of these (and a few more) are already handled by InstCombine,
>>> but we shouldn't have to wait until then to simplify these because
>>> they're cheap to deal with here in InstSimplify.
>>>
>>> Modified:
>>>      llvm/trunk/lib/Analysis/InstructionSimplify.cpp
>>>      llvm/trunk/test/Transforms/InstSimplify/or-icmps-same-ops.ll
>>>
>>> Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/
>>> InstructionSimplify.cpp?rev=288833&r1=288832&r2=288833&view=diff
>>> ============================================================
>>> ==================
>>> --- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
>>> +++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Tue Dec  6 12:09:37
>>> 2016
>>> @@ -1700,12 +1700,44 @@ Value *llvm::SimplifyAndInst(Value *Op0,
>>>                              RecursionLimit);
>>>   }
>>>   -/// Simplify (or (icmp ...) (icmp ...)) to true when we can tell that
>>> the union
>>> -/// contains all possible values.
>>> +/// Commuted variants are assumed to be handled by calling this
>>> function again
>>> +/// with the parameters swapped.
>>> +static Value *simplifyOrOfICmpsWithSameOperands(ICmpInst *Op0,
>>> ICmpInst *Op1) {
>>> +  ICmpInst::Predicate Pred0, Pred1;
>>> +  Value *A ,*B;
>>> +  match(Op0, m_ICmp(Pred0, m_Value(A), m_Value(B)));
>>> +  if (match(Op1, m_ICmp(Pred1, m_Specific(B), m_Specific(A))))
>>> +    Op1->swapOperands();
>>>
>>
>> Is InstSimplify allowed to mutate instructions?
>>
>> -Eli
>>
>>
>> --
>> 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/20161206/39f5bbba/attachment.html>


More information about the llvm-commits mailing list