[PATCH] D138815: [InstSimplify] Fold (X || Y) ? X : Y --> X
chenglin.bi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 29 06:55:25 PST 2022
bcl5980 added inline comments.
================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:4558
+ // (X || Y) ? X : Y --> X (commuted 2 ways)
+ if (match(Cond, m_c_LogicalOr(m_Specific(TrueVal), m_Specific(FalseVal))))
----------------
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());
}
```
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138815/new/
https://reviews.llvm.org/D138815
More information about the llvm-commits
mailing list