Improve dead code elimination

This commit is contained in:
Justine Tunney 2021-02-08 04:04:42 -08:00
parent 760db8c5ad
commit 0e36cb3ac4
6606 changed files with 9685 additions and 9854 deletions

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/bits/bits.h"
#include "libc/bits/progn.internal.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
@ -27,41 +26,18 @@
TEST(division, testUnsigned) {
volatile uint128_t x;
EXPECT_EQ(U(20769187431582143),
PROGN(x = U(1000000000123123123), (U(1125899906842624) << 64) / x));
x = U(1000000000123123123);
EXPECT_EQ(U(20769187431582143), (U(1125899906842624) << 64) / x);
x = U(42);
EXPECT_EQ((U(26807140639110) << 64) | U(1756832768924719201),
PROGN(x = U(42), (U(1125899906842624) << 64) / x));
(U(1125899906842624) << 64) / x);
}
TEST(division, testSigned) {
volatile int128_t x;
EXPECT_EQ(S(20769187431582143),
PROGN(x = S(1000000000123123123), (S(1125899906842624) << 64) / x));
x = S(1000000000123123123);
EXPECT_EQ(S(20769187431582143), (S(1125899906842624) << 64) / x);
x = S(42);
EXPECT_EQ(S(26807140639110) << 64 | S(1756832768924719201),
PROGN(x = S(42), (S(1125899906842624) << 64) / x));
}
BENCH(divmodti4, bench) {
volatile int128_t x;
EZBENCH2("divmodti4 small / small", donothing,
PROGN(x = S(42), x = S(112589990684) / x));
EZBENCH2("divmodti4 small / large", donothing,
PROGN(x = U(123) << 64 | 123, x = S(112589990684) / x));
EZBENCH2("divmodti4 large / small", donothing,
PROGN(x = 123, x = (S(1125899906842624) << 64 | 334) / x));
EZBENCH2(
"divmodti4 large / large", donothing,
PROGN(x = U(123) << 64 | 123, x = (S(1125899906842624) << 64 | 334) / x));
}
BENCH(idiv32, bench) {
volatile int32_t x;
EZBENCH2("idiv32", donothing,
PROGN(x = L(1000000000123123123), x = L(1125899906842624) / x));
}
BENCH(idiv64, bench) {
volatile int64_t x;
EZBENCH2("idiv64", donothing,
PROGN(x = L(1000000000123123123), x = L(1125899906842624) / x));
(S(1125899906842624) << 64) / x);
}

View file

@ -24,7 +24,6 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "libc/bits/progn.internal.h"
#include "libc/bits/pushpop.h"
#include "libc/bits/safemacros.h"
#include "libc/errno.h"
@ -40,7 +39,7 @@
#include "libc/x/x.h"
static char buffer[128];
#define Format(...) PROGN(snprintf(buffer, sizeof(buffer), __VA_ARGS__), buffer)
#define Format(...) gc(xasprintf(__VA_ARGS__))
TEST(sprintf, test_space_flag) {
EXPECT_STREQ(" 42", Format("% d", 42));

View file

@ -17,14 +17,15 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/bits/bits.h"
#include "libc/bits/progn.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/fmt/fmt.h"
#include "libc/runtime/gc.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
static char buffer[128];
#define Format(...) PROGN(snprintf(buffer, sizeof(buffer), __VA_ARGS__), buffer)
#define Format(...) gc(xasprintf(__VA_ARGS__))
/**
* @fileoverview String formatting tests.

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/bits/progn.internal.h"
#include "libc/intrin/mpsadbw.h"
#include "libc/intrin/pabsb.h"
#include "libc/intrin/pabsd.h"
@ -2082,19 +2081,3 @@ TEST(pext, fuzz) {
ASSERT_EQ(pext(x, y), (pext)(x, y));
}
}
BENCH(psrldq, bench) {
volatile uint8_t A[16];
volatile uint8_t B[16];
EZBENCH2("psrldq const 𝑖", donothing, PROGN(psrldq(A, B, 7)));
EZBENCH2("psrldq var 𝑖", donothing, PROGN(psrldq(A, B, VEIL("r", 7))));
EZBENCH2("psrldq ansi", donothing, PROGN((psrldq)(A, B, 7)));
}
BENCH(pslldq, bench) {
volatile uint8_t A[16];
volatile uint8_t B[16];
EZBENCH2("pslldq const 𝑖", donothing, PROGN(pslldq(A, B, 7)));
EZBENCH2("pslldq var 𝑖", donothing, PROGN(pslldq(A, B, VEIL("r", 7))));
EZBENCH2("pslldq ansi", donothing, PROGN((pslldq)(A, B, 7)));
}

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/bits/progn.internal.h"
#include "libc/intrin/palignr.h"
#include "libc/rand/rand.h"
#include "libc/testlib/ezbench.h"
@ -220,12 +219,3 @@ TEST(palignrc, test32orHigher_clearsOutput) {
ASSERT_EQ(0, C[2]);
ASSERT_EQ(0, C[3]);
}
BENCH(palignr, bench) {
volatile __intrin_xmm_t A;
volatile __intrin_xmm_t B;
EZBENCH2("palignr const 𝑖", donothing, PROGN(palignr(&A, &A, &B, 7)));
EZBENCH2("palignr var 𝑖", donothing,
PROGN(palignr(&A, &A, &B, VEIL("r", 7))));
EZBENCH2("palignr ansi", donothing, PROGN((palignr)(&A, &A, &B, 7)));
}

24
test/libc/release/clang.sh Executable file
View file

@ -0,0 +1,24 @@
#!/bin/sh
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
if CLANG=$(command -v clang); then
$COMPILE $CLANG \
-o o/$MODE/test/libc/release/smokeclang.com.dbg \
-Os \
-static \
-no-pie \
-fno-pie \
-nostdlib \
-nostdinc \
-mno-red-zone \
-Wl,--gc-sections \
-Wl,-z,max-page-size=0x1000 \
-Wl,-T,o/$MODE/ape/ape.lds \
-include o/cosmopolitan.h \
test/libc/release/smoke.c \
o/$MODE/libc/crt/crt.o \
o/$MODE/ape/ape.o \
o/$MODE/cosmopolitan.a || exit
o/$MODE/test/libc/release/smokeclang.com.dbg || exit
fi

View file

@ -93,30 +93,15 @@ o/$(MODE)/test/libc/release/smokeansi.com.dbg: \
o/$(MODE)/ape/ape.o \
o/$(MODE)/cosmopolitan.a
o/$(MODE)/test/libc/release/smokeclang.com.dbg: \
o/$(MODE)/test/libc/release/smokeclang.ok: \
test/libc/release/clang.sh \
test/libc/release/smoke.c \
o/cosmopolitan.h \
o/$(MODE)/ape/ape.lds \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape.o \
o/$(MODE)/cosmopolitan.a
@ACTION=CLANG $(COMPILE) clang \
-o $@ \
-Os \
-static \
-no-pie \
-fno-pie \
-nostdlib \
-nostdinc \
-mno-red-zone \
-Wl,--gc-sections \
-Wl,-z,max-page-size=0x1000 \
-Wl,-T,o/$(MODE)/ape/ape.lds \
-include o/cosmopolitan.h \
test/libc/release/smoke.c \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape.o \
o/$(MODE)/cosmopolitan.a
@$<
.PHONY: o/$(MODE)/test/libc/release
o/$(MODE)/test/libc/release: \
@ -125,4 +110,5 @@ o/$(MODE)/test/libc/release: \
o/$(MODE)/test/libc/release/smokecxx.com \
o/$(MODE)/test/libc/release/smokecxx.com.runs \
o/$(MODE)/test/libc/release/smokeansi.com \
o/$(MODE)/test/libc/release/smokeansi.com.runs
o/$(MODE)/test/libc/release/smokeansi.com.runs \
o/$(MODE)/test/libc/release/smokeclang.ok