From owner-freebsd-current@freebsd.org Tue Sep 8 02:10:10 2020 Return-Path: Delivered-To: freebsd-current@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EDEA63DD8E6; Tue, 8 Sep 2020 02:10:10 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "troutmask", Issuer "troutmask" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BlpWj5Y1Pz437w; Tue, 8 Sep 2020 02:10:09 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.16.1/8.16.1) with ESMTPS id 0882A2lq076460 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 7 Sep 2020 19:10:02 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.16.1/8.16.1/Submit) id 0882A22j076459; Mon, 7 Sep 2020 19:10:02 -0700 (PDT) (envelope-from sgk) Date: Mon, 7 Sep 2020 19:10:02 -0700 From: Steve Kargl To: freebsd-toolchain@freebsd.org, freebsd-current@freebsd.org Subject: clang miscompiles OpenLibm on i686-*-freebsd Message-ID: <20200908021002.GA76325@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Rspamd-Queue-Id: 4BlpWj5Y1Pz437w X-Spamd-Bar: / X-Spamd-Result: default: False [-0.46 / 15.00]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-0.63)[-0.628]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; NEURAL_HAM_MEDIUM(-0.33)[-0.329]; NEURAL_SPAM_SHORT(0.49)[0.493]; RCPT_COUNT_TWO(0.00)[2]; R_SPF_NA(0.00)[no SPF record]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:73, ipnet:128.95.0.0/16, country:US]; RCVD_COUNT_TWO(0.00)[2]; MAILMAN_DEST(0.00)[freebsd-toolchain,freebsd-current]; DMARC_POLICY_SOFTFAIL(0.10)[washington.edu : No valid SPF, No valid DKIM, none] X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Sep 2020 02:10:11 -0000 TL;DR summary: clang is broken for numerical on i686 FreeBSD. % uname -a FreeBSD mobile 13.0-CURRENT FreeBSD 13.0-CURRENT #0 r361834M: Fri Jun 5 08:49:26 PDT 2020 obj/usr/src/i386.i386/sys/MOBILE i386 % which clang /usr/bin/clang % clang --version FreeBSD clang version 10.0.1 (git@github.com:llvm/llvm-project.git llvmorg-10.0.1-rc1-0-gf79cd71e145) Target: i386-unknown-freebsd13.0 Thread model: posix InstalledDir: /usr/bin My testing for exp2f(x) shows Interval tested for exp2f: [1,8] ulp <= 0.5: 0.936% 235635 | 0.936% 235635 0.5 < ulp < 0.6: 0.016% 4098 | 0.953% 239733 0.6 < ulp < 0.7: 0.024% 6147 | 0.977% 245880 0.7 < ulp < 0.8: 0.008% 2049 | 0.985% 247929 0.8 < ulp < 0.9: 0.016% 4098 | 1.001% 252027 0.9 < ulp < 1.0: 0.008% 2049 | 1.010% 254076 1.0 < ulp < 1.5: 0.334% 84009 | 1.343% 338085 1.5 < ulp < 2.0: 0.187% 47127 | 1.531% 385212 2.0 < ulp < 3.0: 0.839% 211047 | 2.369% 596259 3.0 < ulp < 0.0: 97.631% 24569565 | 100.000% 25165824 Max ulp: 359512.000000 at 1.96875286e+00 which is bad (ulp means errors in the Unit of Last Place). By default OpenLibm uses "-march=i686 -O3 -m32" on an i686 target. The commandline used in compiling s_exp2f.c is clang -fno-builtin -fno-strict-aliasing -O3 -fPIC -march=i686 -m32 -std=c99 -Wall -I/usr/home/kargl/tmp/olibm -I/usr/home/kargl/tmp/olibm/include -I/usr/home/kargl/tmp/olibm/i387 -I/usr/home/kargl/tmp/olibm/src -DASSEMBLER -D__BSD_VISIBLE -Wno-implicit-function-declaration -I/usr/home/kargl/tmp/olibm/ld80 -c src/s_exp2f.c -o src/s_exp2f.c.o If I use -O1 or -O2 I get the same above results. If I change to -O0, I get clang -fno-builtin -fno-strict-aliasing -O0 -fPIC -march=i686 -m32 -std=c99 -Wall -I/usr/home/kargl/tmp/olibm -I/usr/home/kargl/tmp/olibm/include -I/usr/home/kargl/tmp/olibm/i387 -I/usr/home/kargl/tmp/olibm/src -DASSEMBLER -D__BSD_VISIBLE -Wno-implicit-function-declaration -I/usr/home/kargl/tmp/olibm/ld80 -c src/s_exp2f.c -o src/s_exp2f.c.o Interval tested for exp2f: [1,8] ulp <= 0.5: 0.056% 14072 | 0.056% 14072 0.5 < ulp < 0.6: 0.000% 8 | 0.056% 14080 3.0 < ulp < 0.0: 99.944% 25151744 | 100.000% 25165824 Max ulp: 22729.386719 at 1.00195301e+00 This is better, but still bad. If I remove -m32, I get clang -fno-builtin -fno-strict-aliasing -O0 -fPIC -march=i686 -std=c99 -Wall -I/usr/home/kargl/tmp/olibm -I/usr/home/kargl/tmp/olibm/include -I/usr/home/kargl/tmp/olibm/i387 -I/usr/home/kargl/tmp/olibm/src -DASSEMBLER -D__BSD_VISIBLE -Wno-implicit-function-declaration -I/usr/home/kargl/tmp/olibm/ld80 -c src/s_exp2f.c -o src/s_exp2f.c.o Interval tested for exp2f: [1,8] ulp <= 0.5: 99.959% 25155610 | 99.959% 25155610 0.5 < ulp < 0.6: 0.041% 10214 | 100.000% 25165824 Max ulp: 0.500980 at 1.97115958e+00 This is good, but unoptimized. If I use -O1, -O2, or -O3 without -m32, I get the initial bad results above. If I change -march=i686 to -march=pentiumpro, I get the same results. Theoretically, OpenLibm would test for SSE capabilities and choose a better -march, but it doesn't. This, however, is unimportant. Any port that uses clang (or cc) that does numerical computation and uses -march=i686 (or pentiumpro) is likely broken. -- Steve