[PATCH] D86843: [EarlyCSE] Equivalent SELECTs should hash equally
Bryan Chan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 29 19:11:13 PDT 2020
bryanpkc updated this revision to Diff 288823.
bryanpkc added a comment.
Moved the fix into `matchSelectWithOptionalNotCond` instead of duplicating code.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D86843/new/
https://reviews.llvm.org/D86843
Files:
llvm/lib/Transforms/Scalar/EarlyCSE.cpp
Index: llvm/lib/Transforms/Scalar/EarlyCSE.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -191,6 +191,18 @@
Pred = ICmpInst::getSwappedPredicate(Pred);
}
+ // Check for inverted variants of min/max by swapping operands.
+ switch (Pred) {
+ case CmpInst::ICMP_ULE:
+ case CmpInst::ICMP_UGE:
+ case CmpInst::ICMP_SLE:
+ case CmpInst::ICMP_SGE:
+ Pred = CmpInst::getInversePredicate(Pred);
+ std::swap(A, B);
+ default:
+ break;
+ }
+
switch (Pred) {
case CmpInst::ICMP_UGT: Flavor = SPF_UMAX; break;
case CmpInst::ICMP_ULT: Flavor = SPF_UMIN; break;
@@ -257,6 +269,25 @@
Value *X, *Y;
if (!match(Cond, m_Cmp(Pred, m_Value(X), m_Value(Y))))
return hash_combine(Inst->getOpcode(), Cond, A, B);
+#if 0
+ // Prefer to hash the select as a min/max if possible.
+ CmpInst::Predicate InvPred = CmpInst::getInversePredicate(Pred);
+ if (X == B && Y == A) {
+ switch (InvPred) {
+ case CmpInst::ICMP_UGT: SPF = SPF_UMAX; break;
+ case CmpInst::ICMP_ULT: SPF = SPF_UMIN; break;
+ case CmpInst::ICMP_SGT: SPF = SPF_SMAX; break;
+ case CmpInst::ICMP_SLT: SPF = SPF_SMIN; break;
+ default: break;
+ }
+ if (SPF == SPF_SMIN || SPF == SPF_SMAX ||
+ SPF == SPF_UMIN || SPF == SPF_UMAX) {
+ if (A > B)
+ std::swap(A, B);
+ return hash_combine(Inst->getOpcode(), SPF, A, B);
+ }
+ }
+#endif
// Similar to cmp normalization (above) - canonicalize the predicate value:
// select (icmp Pred, X, Y), A, B --> select (icmp InvPred, X, Y), B, A
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86843.288823.patch
Type: text/x-patch
Size: 1689 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200830/4ff5fe8e/attachment.bin>
More information about the llvm-commits
mailing list