From c187fa12f1a095c9c3c07569c0e965c831c67ace Mon Sep 17 00:00:00 2001
From: Brandt Bucher <brandtbucher@microsoft.com>
Date: Tue, 22 Feb 2022 15:46:54 -0800
Subject: [PATCH 1/3] Don't deopt COMPARE_OP when collecting stats

---
 Python/specialize.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/Python/specialize.c b/Python/specialize.c
index b46f7014289232..da3ceed91c1ec1 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -2014,9 +2014,15 @@ _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs,
     int op = adaptive->original_oparg;
     int next_opcode = _Py_OPCODE(instr[1]);
     if (next_opcode != POP_JUMP_IF_FALSE && next_opcode != POP_JUMP_IF_TRUE) {
-        // Can't ever combine, so don't don't bother being adaptive.
-        SPECIALIZATION_FAIL(COMPARE_OP, SPEC_FAIL_COMPARE_OP_NOT_FOLLOWED_BY_COND_JUMP);
+        // Can't ever combine, so don't don't bother being adaptive (unless
+        // we're collecting stats, where it's more important to get accurate hit
+        // counts for the unadaptive version and each of the different failure
+        // types):
+#ifndef Py_STATS
         *instr = _Py_MAKECODEUNIT(COMPARE_OP, adaptive->original_oparg);
+        return;
+#endif
+        SPECIALIZATION_FAIL(COMPARE_OP, SPEC_FAIL_COMPARE_OP_NOT_FOLLOWED_BY_COND_JUMP);
         goto failure;
     }
     assert(op <= Py_GE);

From fedbd8c9a9bff92c5b0c6544d98e627650a83123 Mon Sep 17 00:00:00 2001
From: Brandt Bucher <brandtbucher@microsoft.com>
Date: Tue, 22 Feb 2022 15:48:45 -0800
Subject: [PATCH 2/3] blurb add

---
 .../Core and Builtins/2022-02-22-15-48-32.bpo-45885.W2vkaI.rst   | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-02-22-15-48-32.bpo-45885.W2vkaI.rst

diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-02-22-15-48-32.bpo-45885.W2vkaI.rst b/Misc/NEWS.d/next/Core and Builtins/2022-02-22-15-48-32.bpo-45885.W2vkaI.rst
new file mode 100644
index 00000000000000..9ddda3c3907e8f
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-02-22-15-48-32.bpo-45885.W2vkaI.rst	
@@ -0,0 +1 @@
+Don't deopt :opcode:`COMPARE_OP` when collecting stats.

From 9980743426b63b15660f952b0aa0342e1d90e1b9 Mon Sep 17 00:00:00 2001
From: Brandt Bucher <brandtbucher@microsoft.com>
Date: Tue, 22 Feb 2022 15:56:44 -0800
Subject: [PATCH 3/3] Fix wording

---
 .../Core and Builtins/2022-02-22-15-48-32.bpo-45885.W2vkaI.rst  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-02-22-15-48-32.bpo-45885.W2vkaI.rst b/Misc/NEWS.d/next/Core and Builtins/2022-02-22-15-48-32.bpo-45885.W2vkaI.rst
index 9ddda3c3907e8f..4339f501fd3fb2 100644
--- a/Misc/NEWS.d/next/Core and Builtins/2022-02-22-15-48-32.bpo-45885.W2vkaI.rst	
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-02-22-15-48-32.bpo-45885.W2vkaI.rst	
@@ -1 +1 @@
-Don't deopt :opcode:`COMPARE_OP` when collecting stats.
+Don't un-adapt :opcode:`COMPARE_OP` when collecting specialization stats.