Skip to content

Commit 08c1464

Browse files
committed
Add constant narrowing for str EQ, NE
1 parent b8b217b commit 08c1464

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

Python/optimizer_bytecodes.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,17 @@ dummy_func(void) {
548548
}
549549

550550
op(_COMPARE_OP_STR, (left, right -- res, l, r)) {
551-
res = sym_new_type(ctx, &PyBool_Type);
551+
int cmp_mask = oparg & (COMPARE_LT_MASK | COMPARE_GT_MASK | COMPARE_EQ_MASK);
552+
553+
if (cmp_mask == COMPARE_EQ_MASK) {
554+
res = sym_new_predicate(ctx, left, right, JIT_PRED_EQ);
555+
}
556+
else if (cmp_mask == (COMPARE_LT_MASK | COMPARE_GT_MASK)) {
557+
res = sym_new_predicate(ctx, left, right, JIT_PRED_NE);
558+
}
559+
else {
560+
res = sym_new_type(ctx, &PyBool_Type);
561+
}
552562
l = left;
553563
r = right;
554564
REPLACE_OPCODE_IF_EVALUATES_PURE(left, right, res);

Python/optimizer_cases.c.h

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)