diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c index 9d2de55e29499..03b59eea61535 100644 --- a/ext/opcache/jit/zend_jit_trace.c +++ b/ext/opcache/jit/zend_jit_trace.c @@ -4510,6 +4510,12 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par op2_info = OP2_INFO(); op2_addr = OP2_REG_ADDR(); if ((op1_info & MAY_BE_UNDEF) || (op2_info & MAY_BE_UNDEF)) { + if (op1_type == IS_LONG || op1_type == IS_DOUBLE) { + CHECK_OP1_TRACE_TYPE(); + } + if (op2_type == IS_LONG || op2_type == IS_DOUBLE) { + CHECK_OP2_TRACE_TYPE(); + } break; } if (opline->opcode == ZEND_ADD && @@ -4518,6 +4524,12 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par /* pass */ } else if (!(op1_info & (MAY_BE_LONG|MAY_BE_DOUBLE)) || !(op2_info & (MAY_BE_LONG|MAY_BE_DOUBLE))) { + if (op1_type == IS_LONG || op1_type == IS_DOUBLE) { + CHECK_OP1_TRACE_TYPE(); + } + if (op2_type == IS_LONG || op2_type == IS_DOUBLE) { + CHECK_OP2_TRACE_TYPE(); + } break; } if (orig_op1_type != IS_UNKNOWN diff --git a/ext/opcache/tests/jit/gh20838.inc b/ext/opcache/tests/jit/gh20838.inc new file mode 100644 index 0000000000000..997cc23b8fee8 --- /dev/null +++ b/ext/opcache/tests/jit/gh20838.inc @@ -0,0 +1,53 @@ + $value) { + if ($k[$key]['st'] == 'correction') $s += $value; + else { + if ($k[$key]['st'] == 'caa') $value = $value / $avc[$key]; + $s += $value / 5 * $k[$key]['tp'] * (1 + 50 / $k[$key]['tp'] * $pav / (100 * $c)); + } + } + } + + echo("$id $s\n"); + + return $s; +} diff --git a/ext/opcache/tests/jit/gh20838.phpt b/ext/opcache/tests/jit/gh20838.phpt new file mode 100644 index 0000000000000..bccf0a0ed8c3e --- /dev/null +++ b/ext/opcache/tests/jit/gh20838.phpt @@ -0,0 +1,66 @@ +--TEST-- +GH-20838 (JIT compiler produces wrong arithmetic results) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.jit=tracing +opcache.jit_buffer_size=64M +opcache.jit_hot_loop=61 +opcache.jit_hot_func=127 +opcache.jit_hot_return=8 +opcache.jit_hot_side_exit=8 +--EXTENSIONS-- +opcache +--FILE_EXTERNAL-- +gh20838.inc +--EXPECT-- +49 0 +1080 18 +4415 31.25 +4763 75 +4926 75 +4933 60 +4935 75 +4938 75 +4939 75 +4947 60 +4952 45 +4953 75 +4962 60 +8558 45 +14888 45 +16879 13 +100003 0 +100007 60 +100013 0 +100017 13 +100019 15 +100027 45 +100031 30 +106427 -37.5 +217955 -9 +240000 30 +240010 60 +240021 45 +240079 112.66666666667 +240210 45 +240227 45 +240249 75 +240273 75 +240333 30 +240335 60 +300024 96.5 +310001 45 +310025 45 +310034 60 +310042 30 +310111 75 +310191 45 +310219 75 +310236 15 +310322 45 +310356 30 +310360 21.25 +310394 29.5 +310405 75 +310411 60