[PATCH] D47922: unsigned foo(unsigned x, unsigned y) { return x > y && x != 0; } should fold to x > y

Li Jia He via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 11 00:05:47 PDT 2018


HLJ2009 added inline comments.


================
Comment at: lib/Analysis/InstructionSimplify.cpp:1312-1316
   if (match(UnsignedICmp, m_ICmp(UnsignedPred, m_Value(X), m_Specific(Y))) &&
       ICmpInst::isUnsigned(UnsignedPred))
     ;
   else if (match(UnsignedICmp,
-                 m_ICmp(UnsignedPred, m_Value(Y), m_Specific(X))) &&
----------------
lebedev.ri wrote:
> After staring at this a bit more, the original code looks like just a dead code.
> We are first trying to match `match(UnsignedICmp, m_ICmp(UnsignedPred, m_Value(X), m_Specific(Y))`.
> I.e. we take whatever `X`, and the specific value of `Y`. This could match.
> And then we check that `ICmpInst::isUnsigned(UnsignedPred)` is true. This could fail.
> Then we fall back to `else if`.
> And use `match(UnsignedICmp, m_ICmp(UnsignedPred, m_Value(Y), m_Specific(X))`.
> But this could not possibly match, because the first time we took `X` from the first operand,
> and now we are looking for this very `X` in the second operand.
> And the `m_ICmp()` is not commutable.
> So i think this is simply a typo.
Yes, your analysis is the same as mine.


Repository:
  rL LLVM

https://reviews.llvm.org/D47922





More information about the llvm-commits mailing list