(X || Y) ? X : Y --> X
https://alive2.llvm.org/ce/z/oRQJee
Details
Details
- Reviewers
- spatel - liaolucy 
- Commits
- rGf2973327496f: [InstSimplify] Fold (X || Y) ? X : Y --> X
Diff Detail
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
| llvm/lib/Analysis/InstructionSimplify.cpp | ||
|---|---|---|
| 4558 | Hi @spatel , which way do you think is better here? // (X || Y) ? X : Y --> X (commuted 2 ways)
if (match(Cond, m_c_LogicalOr(m_Specific(TrueVal), m_Specific(FalseVal))))
  return TrueVal;
// (X || Y) ? false : X --> false (commuted 2 ways)
if (match(Cond, m_c_LogicalOr(m_Specific(FalseVal), m_Value())) &&
    match(TrueVal, m_ZeroInt()))
  return ConstantInt::getFalse(Cond->getType());or if (match(Cond, m_LogicalOr(m_Value(X), m_Value(Y)))) {
  // (X || Y) ? X : Y --> X
  if ((X == TrueVal && Y == FalseVal) || (X == FalseVal && Y == TrueVal))
    return TrueVal;
  // (X || Y) ? false : X --> false (commuted 2 ways)
  if (match(TrueVal, m_ZeroInt()) && (X == FalseVal || Y == FalseVal))
    return ConstantInt::getFalse(Cond->getType());
} | |
Hi @spatel , which way do you think is better here?
// (X || Y) ? X : Y --> X (commuted 2 ways) if (match(Cond, m_c_LogicalOr(m_Specific(TrueVal), m_Specific(FalseVal)))) return TrueVal; // (X || Y) ? false : X --> false (commuted 2 ways) if (match(Cond, m_c_LogicalOr(m_Specific(FalseVal), m_Value())) && match(TrueVal, m_ZeroInt())) return ConstantInt::getFalse(Cond->getType());or
if (match(Cond, m_LogicalOr(m_Value(X), m_Value(Y)))) { // (X || Y) ? X : Y --> X if ((X == TrueVal && Y == FalseVal) || (X == FalseVal && Y == TrueVal)) return TrueVal; // (X || Y) ? false : X --> false (commuted 2 ways) if (match(TrueVal, m_ZeroInt()) && (X == FalseVal || Y == FalseVal)) return ConstantInt::getFalse(Cond->getType()); }