Subject: bug#46540: 28.0.50; Native-comp optimization bug

From: Pip Cet <[email-masked]>
Date: Wed, 17 Feb 2021 07:50:00 +0000

On Tue, Feb 16, 2021 at 9:44 PM Andrea Corallo wrote:
> The following constrain insn clearly resolves in the wrong way:
>
> (assume #(mvar 79140560 0 (integer 0 0)) (<= #(mvar 79118120 0 (integer 0 *)) #(mvar 79118988 3 (integer 0 *))))
>
> Will come-up with a fix.

My guess is that this code in comp-cstr.el:

(defun comp-cstr-<= (dst old-dst src)
  "Constraint DST being <= than SRC.
SRC can be either a comp-cstr or an integer."
  (with-comp-cstr-accessors
    (let ((ext-range
           (if (integerp src)
               `((- . ,src))
             (when-let* ((range (range src))
                         (low (comp-cstr-smallest-in-range range))
                         (okay (integerp low)))
               `((- . ,low))))))
      (comp-cstr-set-cmp-range dst old-dst ext-range))))

should use comp-cstr-greatest-in-range rather than
comp-cstr-smallest-in-range. Same for comp-cstr-<. Analogous for
comp-cstr->, comp-cstr->=.

(If A's possible values are {3, 4, 5}, and B is <= A, we can only
conclude B <= 5, not that B <= 3, since A = 5, B = 5 is a solution to
the constraint problem).