Combining comparisons in three-way branching

Bug #1847284 reported by Paul F. Dietz on 2019-10-08
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

(declaim (optimize speed (safety 0)))

(defun f (x y) (declare (type fixnum x y)) (if (> x y) 1 (if (= y x) 2 3)))

(disassemble 'f) ==>

; disassembly for F
; Size: 36 bytes. Origin: #x52D781E6
; 1E6: 4839FA CMP RDX, RDI ; no-arg-parsing entry point
; 1E9: 7F18 JNLE L1
; 1EB: 4839FA CMP RDX, RDI
; 1EE: BA06000000 MOV EDX, 6
; 1F3: 41BB04000000 MOV R11D, 4
; 1F9: 490F44D3 CMOVEQ RDX, R11
; 1FD: L0: 488BE5 MOV RSP, RBP
; 200: F8 CLC
; 201: 5D POP RBP
; 202: C3 RET
; 203: L1: BA02000000 MOV EDX, 2
; 208: EBF3 JMP L0

The two comparisons at 1E6 and 1EB appear redundant. Can these be combined somehow? And similarly for other order comparison functions (string<, string-less-than, char<).

Stas Boukarev (stassats) wrote :


Changed in sbcl:
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers