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

Friedman, Eli via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 6 13:18:37 PST 2016


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



More information about the llvm-commits mailing list