[PATCH] D64285: [InstCombine] Fold select (icmp sgt x, -1), lshr (X, Y), ashr (X, Y) to ashr (X, Y))

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 11 06:23:57 PDT 2019


lebedev.ri added inline comments.


================
Comment at: lib/Analysis/InstructionSimplify.cpp:92-93
+        match(CmpLHS, m_Specific(X))) {
+      if (!cast<BinaryOperator>(TrueVal)->isExact() &&
+          cast<BinaryOperator>(FalseVal)->isExact())
+        return nullptr;
----------------
lebedev.ri wrote:
> ```
> /// If either the `ashr` is non-`exact`, or `lshr` is exact too, then we can just return the `ashr` instruction.
> ```
> i think it may be less confusing to flip the `if` accordingly.
Hmm, also, as i've recently seen, `cast<BinaryOperator>` is going to break for constant expressions.
Let's just do the most obvious thing instead:
```
if (match(TrueVal, m_LShr(m_Value(X), m_Value(Y))) &&
    match(FalseVal, m_AShr(m_Specific(X), m_Specific(Y))) &&
    match(CmpLHS, m_Specific(X)) && 
    (!match(FalseVal, m_Exact()) || match(TrueVal, m_Exact())))
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64285/new/

https://reviews.llvm.org/D64285





More information about the llvm-commits mailing list