summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-12-13 22:57:35 +0000
committerSanjay Patel <spatel@rotateright.com>2017-12-13 22:57:35 +0000
commit558a465473bde9dfae7f17ff4be2f638586624b9 (patch)
tree2fe4b54b484351f7aa26e9e8e2753e6755dbda0a /llvm/lib/Transforms
parentd44a81c3a8aefbb08ed85bb653480451b9586853 (diff)
downloadbcm5719-llvm-558a465473bde9dfae7f17ff4be2f638586624b9.tar.gz
bcm5719-llvm-558a465473bde9dfae7f17ff4be2f638586624b9.zip
[EarlyCSE] recognize swapped variants of abs/nabs as equivalent
Extends https://reviews.llvm.org/rL320640 Differential Revision: https://reviews.llvm.org/D41136 llvm-svn: 320653
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/EarlyCSE.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
index 11bf8ee733c..5798e1c4ee9 100644
--- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -143,14 +143,16 @@ unsigned DenseMapInfo<SimpleValue>::getHashValue(SimpleValue Val) {
return hash_combine(Inst->getOpcode(), Pred, LHS, RHS);
}
- // Hash min/max (cmp + select) to allow for commuted operands, non-canonical
- // compare predicate (eg, the compare for smin may use 'sgt' rather than
- // 'slt'), and non-canonical operands in the compare.
+ // Hash min/max/abs (cmp + select) to allow for commuted operands.
+ // Min/max may also have non-canonical compare predicate (eg, the compare for
+ // smin may use 'sgt' rather than 'slt'), and non-canonical operands in the
+ // compare.
Value *A, *B;
SelectPatternFlavor SPF = matchSelectPattern(Inst, A, B).Flavor;
- // TODO: We should also detect abs and FP min/max.
+ // TODO: We should also detect FP min/max.
if (SPF == SPF_SMIN || SPF == SPF_SMAX ||
- SPF == SPF_UMIN || SPF == SPF_UMAX) {
+ SPF == SPF_UMIN || SPF == SPF_UMAX ||
+ SPF == SPF_ABS || SPF == SPF_NABS) {
if (A > B)
std::swap(A, B);
return hash_combine(Inst->getOpcode(), SPF, A, B);
@@ -214,13 +216,14 @@ bool DenseMapInfo<SimpleValue>::isEqual(SimpleValue LHS, SimpleValue RHS) {
LHSCmp->getSwappedPredicate() == RHSCmp->getPredicate();
}
- // Min/max can occur with commuted operands, non-canonical predicates, and/or
- // non-canonical operands.
+ // Min/max/abs can occur with commuted operands, non-canonical predicates,
+ // and/or non-canonical operands.
Value *LHSA, *LHSB;
SelectPatternFlavor LSPF = matchSelectPattern(LHSI, LHSA, LHSB).Flavor;
- // TODO: We should also detect abs and FP min/max.
+ // TODO: We should also detect FP min/max.
if (LSPF == SPF_SMIN || LSPF == SPF_SMAX ||
- LSPF == SPF_UMIN || LSPF == SPF_UMAX) {
+ LSPF == SPF_UMIN || LSPF == SPF_UMAX ||
+ LSPF == SPF_ABS || LSPF == SPF_NABS) {
Value *RHSA, *RHSB;
SelectPatternFlavor RSPF = matchSelectPattern(RHSI, RHSA, RHSB).Flavor;
return (LSPF == RSPF && ((LHSA == RHSA && LHSB == RHSB) ||
OpenPOWER on IntegriCloud