[llvm-commits] [llvm] r45250 - /llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Evan Cheng
evan.cheng at apple.com
Wed Dec 19 18:46:34 PST 2007
Hi Chris,
Are you forgetting PatternMatch.h? m_Zero isn't defined anywhere.
Evan
On Dec 19, 2007, at 5:56 PM, Chris Lattner wrote:
> Author: lattner
> Date: Wed Dec 19 19:56:58 2007
> New Revision: 45250
>
> URL: http://llvm.org/viewvc/llvm-project?rev=45250&view=rev
> Log:
> simplify this code with the new m_Zero() pattern. Make sure the
> select only
> has a single use, and generalize it to not require N to be a constant.
>
>
> Modified:
> llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
>
> Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/
> Scalar/InstructionCombining.cpp?rev=45250&r1=45249&r2=45250&view=diff
>
> ======================================================================
> ========
> --- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
> (original)
> +++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Wed
> Dec 19 19:56:58 2007
> @@ -2109,8 +2109,7 @@
> }
>
> // add (cast *A to intptrtype) B ->
> - // cast (GEP (cast *A to sbyte*) B) ->
> - // intptrtype
> + // cast (GEP (cast *A to sbyte*) B) --> intptrtype
> {
> CastInst *CI = dyn_cast<CastInst>(LHS);
> Value *Other = RHS;
> @@ -2131,8 +2130,7 @@
> }
> }
>
> - // add (select X 0 (sub n A)) A ->
> - // select X A n
> + // add (select X 0 (sub n A)) A --> select X A n
> {
> SelectInst *SI = dyn_cast<SelectInst>(LHS);
> Value *Other = RHS;
> @@ -2140,25 +2138,19 @@
> SI = dyn_cast<SelectInst>(RHS);
> Other = LHS;
> }
> - if (SI) {
> + if (SI && SI->hasOneUse()) {
> Value *TV = SI->getTrueValue();
> Value *FV = SI->getFalseValue();
> - Value *A;
> + Value *A, *N;
>
> // Can we fold the add into the argument of the select?
> // We check both true and false select arguments for a
> matching subtract.
> - ConstantInt *C1, *C2;
> - if (match(FV, m_ConstantInt(C1)) && C1->getValue() == 0 &&
> - match(TV, m_Sub(m_ConstantInt(C2), m_Value(A))) &&
> - A == Other) {
> - // We managed to fold the add into the true select value.
> - return new SelectInst(SI->getCondition(), C2, A);
> - } else if (match(TV, m_ConstantInt(C1)) && C1->getValue() ==
> 0 &&
> - match(FV, m_Sub(m_ConstantInt(C2), m_Value(A))) &&
> - A == Other) {
> - // We managed to fold the add into the false select value.
> - return new SelectInst(SI->getCondition(), A, C2);
> - }
> + if (match(FV, m_Zero()) && match(TV, m_Sub(m_Value(N),
> m_Value(A))) &&
> + A == Other) // Fold the add into the true select value.
> + return new SelectInst(SI->getCondition(), N, A);
> + if (match(TV, m_Zero()) && match(FV, m_Sub(m_Value(N),
> m_Value(A))) &&
> + A == Other) // Fold the add into the false select value.
> + return new SelectInst(SI->getCondition(), A, N);
> }
> }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list