The native compiler should not try to generate in rendered code
immediate floats produced by the constrain on the '=' operator.
* test/src/comp-tests.el (comp-test-78606-1): Add test.
* test/src/comp-resources/comp-test-funcs.el (comp-test-78606-1-f): New
function.
* src/comp.c (emit_mvar_rval): Check if an immediate is materializable.
* lisp/emacs-lisp/comp.el (comp-ctxt): Add 'non-materializable-objs-h'
slot.
(comp--fwprop-insn): Update call.
* lisp/emacs-lisp/comp-cstr.el (comp-cstr-=): Add parameter.
(cherry picked from commit
48a5917681dd53b8b75764f4e1455a6c24f95498)
(and (comp-cstr-cl-tag-p cstr)
(intern (match-string 1 (symbol-name (car (valset cstr))))))))
-(defun comp-cstr-= (dst op1 op2)
- "Constraint OP1 being = OP2 setting the result into DST."
+(defun comp-cstr-= (dst op1 op2 nm-objs-h)
+ "Constraint OP1 being = OP2 setting the result into DST.
+NM-OBJS-H is an hash with all the immediates generated at compile time
+which should not be rendered into compiled code."
(with-comp-cstr-accessors
(cl-flet ((relax-cstr (cstr)
(setf cstr (copy-sequence cstr))
else
do (cl-pushnew 'float (typeset cstr))
(cl-return cstr)
- finally (setf (valset cstr)
- (append vals-to-add (valset cstr))))
+ finally
+ (mapc (lambda (x) (puthash x t nm-objs-h))
+ vals-to-add)
+ (setf (valset cstr)
+ (append vals-to-add (valset cstr))))
(when (memql 0.0 (valset cstr))
(cl-pushnew -0.0 (valset cstr)))
(when (memql -0.0 (valset cstr))
:documentation "Standard data relocated in use by functions.")
(d-ephemeral (make-comp-data-container) :type comp-data-container
:documentation "Relocated data not necessary after load.")
+ (non-materializable-objs-h (make-hash-table :test #'equal) :type hash-table
+ :documentation "Objects produced by the propagation engine which can't be materialized.
+Typically floating points (which are not cons-hashed).")
(with-late-load nil :type boolean
:documentation "When non-nil support late load."))
(<=
(comp-cstr-<= lval (car operands) (cadr operands)))
(=
- (comp-cstr-= lval (car operands) (cadr operands)))))
+ (comp-cstr-= lval (car operands) (cadr operands)
+ (comp-ctxt-non-materializable-objs-h comp-ctxt)))))
(`(setimm ,lval ,v)
(setf (comp-cstr-imm lval) v))
(`(phi ,lval . ,rest)
if (!NILP (const_vld))
{
Lisp_Object value = CALLNI (comp-cstr-imm, mvar);
- if (comp.debug > 1)
+ if (NILP (Fgethash (value,
+ CALLNI (comp-ctxt-non-materializable-objs-h, Vcomp_ctxt),
+ Qnil)))
{
- Lisp_Object func =
- Fgethash (value,
- CALLNI (comp-ctxt-byte-func-to-func-h, Vcomp_ctxt),
- Qnil);
-
- emit_comment (
- SSDATA (
- Fprin1_to_string (
- NILP (func) ? value : CALLNI (comp-func-c-name, func),
- Qnil, Qnil)));
- }
- if (FIXNUMP (value))
- {
- /* We can still emit directly objects that are self-contained in a
- word (read fixnums). */
- return emit_rvalue_from_lisp_obj (value);
+ if (comp.debug > 1)
+ {
+ Lisp_Object func =
+ Fgethash (value,
+ CALLNI (comp-ctxt-byte-func-to-func-h, Vcomp_ctxt),
+ Qnil);
+
+ emit_comment (
+ SSDATA (
+ Fprin1_to_string (
+ NILP (func) ? value : CALLNI (comp-func-c-name, func),
+ Qnil, Qnil)));
+ }
+ if (FIXNUMP (value))
+ {
+ /* We can still emit directly objects that are self-contained in a
+ word (read fixnums). */
+ return emit_rvalue_from_lisp_obj (value);
+ }
+ /* Other const objects are fetched from the reloc array. */
+ return emit_lisp_obj_rval (value);
}
- /* Other const objects are fetched from the reloc array. */
- return emit_lisp_obj_rval (value);
}
return gcc_jit_lvalue_as_rvalue (emit_mvar_lval (mvar));
(defun comp-test-76573-1-f ()
(record 'undeclared-type))
+(defun comp-test-78606-1-f (x)
+ (and (= x 1)
+ (if (eql x 1)
+ 1
+ x)))
+
\f
;;;;;;;;;;;;;;;;;;;;
;; Tromey's tests ;;
"<https://lists.gnu.org/archive/html/bug-gnu-emacs/2024-09/msg00794.html>"
(should (eq (comp-test-73270-1-f (make-comp-test-73270-child4)) 'child4)))
+(comp-deftest comp-test-78606-1 ()
+ "<https://lists.gnu.org/archive/html/bug-gnu-emacs/2025-05/msg01270.html>"
+ (should (let ((x 1.0))
+ (eq (comp-test-78606-1-f x) x))))
+
\f
;;;;;;;;;;;;;;;;;;;;;
;; Tromey's tests. ;;