From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id EE3997EE34 for ; Wed, 30 Mar 2016 01:07:02 +0200 (CEST) IronPort-PHdr: 9a23:a6dn2xTtH71Xg+E+7mxPzPRftdpsv+yvbD5Q0YIujvd0So/mwa64ZxeN2/xhgRfzUJnB7Loc0qyN4/CmAzNLuM3JmUtBWaIPfidNsd8RkQ0kDZzNImzAB9muURYHGt9fXkRu5XCxPBsdMs//Y1rPvi/6tmZKSV3BPAZ4bt74BpTVx5zukbviq9uJPE4R33KUWvBbElaflU3prM4YgI9veO4a6yDihT92QdlQ3n5iPlmJnhzxtY+a9Z9n9DlM6bp6r5YTGfayQ6NtRrVdCHEiMnspzMztrxjKCwWVtVUGVWBDqBdFD0D67RXhWZG55iD3uut53CCyMsj/TLRyUjOnufQ4ACT0gTsKYmZquFrcjdZ92fpW Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=cedilla@gmail.com; spf=Pass smtp.mailfrom=cedilla@gmail.com; spf=None smtp.helo=postmaster@mail-ob0-f193.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of cedilla@gmail.com) identity=pra; client-ip=209.85.214.193; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="cedilla@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of cedilla@gmail.com designates 209.85.214.193 as permitted sender) identity=mailfrom; client-ip=209.85.214.193; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="cedilla@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ob0-f193.google.com) identity=helo; client-ip=209.85.214.193; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="postmaster@mail-ob0-f193.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CyAgB4CftWksHWVdFdg1E1fQamcgEGgVcEA4crjHUZhENSghgHPBABAQEBAQEBARABAQEBBwsLCSEvgi2CLREdARseAxIDDTcCJAERAQUBFicah28BAxKSJ406ggeBMT4xizaBaoJXhl4KGScNUYRGAQUKBYVGjEmCVgWOOIk0hXKIFYI0jFmNUhEegQ4PKII/gXEcMIg/AQEB X-IPAS-Result: A0CyAgB4CftWksHWVdFdg1E1fQamcgEGgVcEA4crjHUZhENSghgHPBABAQEBAQEBARABAQEBBwsLCSEvgi2CLREdARseAxIDDTcCJAERAQUBFicah28BAxKSJ406ggeBMT4xizaBaoJXhl4KGScNUYRGAQUKBYVGjEmCVgWOOIk0hXKIFYI0jFmNUhEegQ4PKII/gXEcMIg/AQEB X-IronPort-AV: E=Sophos;i="5.24,413,1454972400"; d="scan'208,217";a="171527148" Received: from mail-ob0-f193.google.com ([209.85.214.193]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 30 Mar 2016 01:07:01 +0200 Received: by mail-ob0-f193.google.com with SMTP id e7so4052920obv.2 for ; Tue, 29 Mar 2016 16:07:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to; bh=W2vyHR479JnIeMsa4zXueupNa7s1Bb2a7bBao7ojhvo=; b=Yd44GAoAwDBIUJ7KoxioXscpOD36S1q5Pf2pyBiPKUQy5Sn/9GO2ewGBaI8bDe321L weAPEdGL4a3KULf3KW0+xD7M95Bltqjs1pmmxeMe1Uoj//hRpiPPUUyM8c7pwMIkyqXW Xhist3uan2D9JN5+ajkAC1HZQNuJzc3hECb5nGBjOIY1uxh238DUlzW5ckv6kh9xtEaJ zNGD6akXxgnL9WtOt9v4c6OLasWUmaQDuULC/qBO1jgj1gNCrIivZ3V1Bs7En82Nl10G 1sGFoKL5123gERA+vdFc6qXy1eLNBaDf3paKNGSSetPqa5iQdpWkThd2VZ6lCsJ67zR4 /3Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to; bh=W2vyHR479JnIeMsa4zXueupNa7s1Bb2a7bBao7ojhvo=; b=YsGGbkfoXfQzDhPlZrrRC648FpW147DqJW1Pe6yctQ3Sklxtoy8YNbWfbXGvke2GBQ BN5kipB25+u+DsKE+84rPgyYynQls3kD/cMB2Vg3QWmgT+SY0QvvD6N+ROj31HuVJ2TO Xe919Q4t3d9uOfei4AqXrRdThoUI6FIaCnoZ8y+k+iki6SB6AogTE7djH08U/N31JIE0 WWUJJ8wRkcs6BywkyvbcPjudoHXCwn0Z/sSYz6rmcBsb9lq21WMB3Bv+BFRAsknRoJl2 Hl7+x6qJMgLFEyTk9XXCCNyib4ylzwkpnewkQTPMaZxU0R7WnmpOeYDfstQXgSqA098C 2+XA== X-Gm-Message-State: AD7BkJKomoM54rhxEYbunweEs1fCFEcB9aXckvr87SPygJTvuIauKT1ZU98EH6OSc79T2XKLg5ONRgrJmj1dnA== MIME-Version: 1.0 X-Received: by 10.157.33.2 with SMTP id i2mr1892928otb.138.1459292819978; Tue, 29 Mar 2016 16:06:59 -0700 (PDT) Received: by 10.76.107.48 with HTTP; Tue, 29 Mar 2016 16:06:59 -0700 (PDT) Date: Tue, 29 Mar 2016 16:06:59 -0700 Message-ID: From: Reed Wilson To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=001a113d1538287f21052f3816ad X-Validation-by: cedilla@gmail.com Subject: [Caml-list] flambda seemingly missing easy optimization --001a113d1538287f21052f3816ad Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi list, I've been playing around with the flambda build of 4.03.0+dev16, and I found some seemingly useless code in the generated assembly and cmm tree that is not returned without flambda. I made a small function to demonstrate it: let compare_str_sub p s s_off len =3D if s_off < 0 || s_off + len > String.length s then invalid_arg "Don't do that!"; else p =3D s The non-flambda cmm is: (function camlTest__compare_str_sub_1199 (p/1200: val s/1201: val s_off/1202: val len/1203: val) (catch (if (< s_off/1202 1) (exit 2) (if (> (+ (+ s_off/1202 len/1203) -1) (+ (<< (let tmp/1206 (- (<< (>>u (load int (+a s/1201 -8)) 10) 3) 1) (- tmp/1206 (load unsigned int8 (+a s/1201 tmp/1206)))) 1) 1)) (exit 2) (extcall "caml_string_equal" p/1200 s/1201 val))) with(2) (app "camlPervasives__invalid_arg_1007" "camlTest__1" val))) flambda results in: (function camlTest__compare_str_sub_4 (p_9/1210: val s_8/1209: val s_off_7/1208: val len_6/1207: val) (catch (catch (if (< s_off_7/1208 1) (if (!=3D 3 1) (exit 2) (exit 3)) (if (!=3D (let Pintcomp_arg_15/1217 (+ (<< (let tmp/1221 (- (<< (>>u (load int (+a s_8/1209 -8)) 10) 3) 1) (- tmp/1221 (load unsigned int8 (+a s_8/1209 tmp/1221)))) 1) 1) (+ (<< (> (+ (+ s_off_7/1208 len_6/1207) -1) Pintcomp_arg_15/1217) 1) 1)) 1) (exit 2) (exit 3))) with(3) (extcall "caml_string_equal" p_9/1210 s_8/1209 val)) with(2) (app{test.ml:18,52-90} "camlPervasives__invalid_arg_279" "camlTest__apply_arg_31" val))) The odd code is toward the beginning: (if (!=3D 3 1) (exit 2) (exit 3)) I don't know a lot about cmm code, but it looks like something the compiler should be able to optimize better. Fiddling with the flambda optimization options doesn't seem to remove it. Is this just due to how new flambda is, or is there some other reason that code makes it through? Thanks, Reed Wlison --=20 =C3=A7 --001a113d1538287f21052f3816ad Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi list,

I've been playing around w= ith the flambda build of 4.03.0+dev16, and I found some seemingly useless c= ode in the generated assembly and cmm tree that is not returned without fla= mbda.

I made a small function to demonstrate it:
let compare_str_sub p s s_off len =3D
if s_off < 0 || s_off + len &= gt; String.length s
= then invalid_arg "Don't do that!";
else p =3D s
The non-flambda cmm is:
(function camlTest__comp= are_str_sub_1199
=C2=A0 =C2=A0 =C2=A0(p/1200: val s/1201: val s_o= ff/1202: val len/1203: val)
=C2=A0(catch
=C2=A0 =C2=A0(= if (< s_off/1202 1) (exit 2)
=C2=A0 =C2=A0 =C2=A0(if
=C2=A0 =C2=A0 =C2=A0 =C2=A0(> (+ (+ s_off/1202 len/1203) -1)
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(+
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0(<<
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(let tmp/1206 (- (<< (>>u (load int (+a s/1201 -8)) 10) 3= ) 1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(- tm= p/1206 (load unsigned int8 (+a s/1201 tmp/1206))))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A01)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A01))
=C2=A0 =C2=A0 =C2=A0 =C2=A0(exit 2) (extcall &qu= ot;caml_string_equal" p/1200 s/1201 val)))
=C2=A0with(2) (ap= p "camlPervasives__invalid_arg_1007" "camlTest__1" val)= ))

flambda results in:
(funct= ion camlTest__compare_str_sub_4
=C2=A0 =C2=A0 =C2=A0(p_9/1210: va= l s_8/1209: val s_off_7/1208: val len_6/1207: val)
=C2=A0(catch
=C2=A0 =C2=A0(catch
=C2=A0 =C2=A0 =C2=A0(if (< s_off_= 7/1208 1) (if (!=3D 3 1) (exit 2) (exit 3))
=C2=A0 =C2=A0 =C2=A0 = =C2=A0(if
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(!=3D
=C2= =A0 =C2=A0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=C2=A01)
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A01))
=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A01)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= (exit 2) (exit 3)))
=C2=A0 =C2=A0with(3) (extcall "caml_stri= ng_equal" p_9/1210 s_8/1209 val))
=C2=A0with(2)
= =C2=A0 =C2=A0(app{test.ml:18,52-90} "= ;camlPervasives__invalid_arg_279"
=C2=A0 =C2=A0 =C2=A0"= camlTest__apply_arg_31" val)))

The odd = code is toward the beginning: (if (!=3D 3 1) (exit 2) (exit 3))
I= don't know a lot about cmm code, but it looks like something the compi= ler should be able to optimize better. Fiddling with the flambda optimizati= on options doesn't seem to remove it.

Is this = just due to how new flambda is, or is there some other reason that code mak= es it through?

Thanks,
Reed Wlison
=

--
=C3=A7
--001a113d1538287f21052f3816ad--