From 96f5fd3089075b56ea9ea85060213cc4edd7251a Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Tue, 3 Dec 2024 12:26:01 -0700 Subject: Move some CRC tests into the gcc.dg/torture directory Jakub noted that these tests were using dg-skip-if directives that implied the tests were expected to run under multiple optimization options, which means they probably should be in gcc.dg/torture rather than in the gcc.dg directory. This moves the relevant tests from gcc.dg to gcc.dg/torture. gcc/testsuite * gcc.dg/crc-linux-1.c: Moved to from gcc.dg/torture. * gcc.dg/crc-linux-2.c: Likewise. * gcc.dg/crc-linux-4.c: Likewise. * gcc.dg/crc-linux-5.c: Likewise. * gcc.dg/crc-not-crc-15.c: Likewise. * gcc.dg/crc-side-instr-1.c: Likewise. * gcc.dg/crc-side-instr-2.c: Likewise. * gcc.dg/crc-side-instr-3.c: Likewise. * gcc.dg/crc-side-instr-4.c: Likewise. * gcc.dg/crc-side-instr-5.c: Likewise. * gcc.dg/crc-side-instr-6.c: Likewise. * gcc.dg/crc-side-instr-7.c: Likewise. * gcc.dg/crc-side-instr-8.c: Likewise. * gcc.dg/crc-side-instr-9.c: Likewise. * gcc.dg/crc-side-instr-10.c: Likewise. * gcc.dg/crc-side-instr-11.c: Likewise. * gcc.dg/crc-side-instr-12.c: Likewise. * gcc.dg/crc-side-instr-13.c: Likewise. * gcc.dg/crc-side-instr-14.c: Likewise. * gcc.dg/crc-side-instr-15.c: Likewise. * gcc.dg/crc-side-instr-16.c: Likewise. * gcc.dg/crc-side-instr-17.c: Likewise. --- gcc/testsuite/gcc.dg/crc-linux-1.c | 45 ------------- gcc/testsuite/gcc.dg/crc-linux-2.c | 65 ------------------- gcc/testsuite/gcc.dg/crc-linux-4.c | 30 --------- gcc/testsuite/gcc.dg/crc-linux-5.c | 81 ------------------------ gcc/testsuite/gcc.dg/crc-not-crc-15.c | 23 ------- gcc/testsuite/gcc.dg/crc-side-instr-1.c | 27 -------- gcc/testsuite/gcc.dg/crc-side-instr-10.c | 31 --------- gcc/testsuite/gcc.dg/crc-side-instr-11.c | 31 --------- gcc/testsuite/gcc.dg/crc-side-instr-12.c | 33 ---------- gcc/testsuite/gcc.dg/crc-side-instr-13.c | 31 --------- gcc/testsuite/gcc.dg/crc-side-instr-14.c | 35 ---------- gcc/testsuite/gcc.dg/crc-side-instr-15.c | 37 ----------- gcc/testsuite/gcc.dg/crc-side-instr-16.c | 38 ----------- gcc/testsuite/gcc.dg/crc-side-instr-17.c | 37 ----------- gcc/testsuite/gcc.dg/crc-side-instr-2.c | 27 -------- gcc/testsuite/gcc.dg/crc-side-instr-3.c | 26 -------- gcc/testsuite/gcc.dg/crc-side-instr-4.c | 26 -------- gcc/testsuite/gcc.dg/crc-side-instr-5.c | 26 -------- gcc/testsuite/gcc.dg/crc-side-instr-6.c | 42 ------------ gcc/testsuite/gcc.dg/crc-side-instr-7.c | 40 ------------ gcc/testsuite/gcc.dg/crc-side-instr-8.c | 36 ----------- gcc/testsuite/gcc.dg/crc-side-instr-9.c | 31 --------- gcc/testsuite/gcc.dg/torture/crc-linux-1.c | 45 +++++++++++++ gcc/testsuite/gcc.dg/torture/crc-linux-2.c | 65 +++++++++++++++++++ gcc/testsuite/gcc.dg/torture/crc-linux-4.c | 30 +++++++++ gcc/testsuite/gcc.dg/torture/crc-linux-5.c | 81 ++++++++++++++++++++++++ gcc/testsuite/gcc.dg/torture/crc-not-crc-15.c | 23 +++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-1.c | 27 ++++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-10.c | 31 +++++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-11.c | 31 +++++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-12.c | 33 ++++++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-13.c | 31 +++++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-14.c | 35 ++++++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-15.c | 37 +++++++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-16.c | 38 +++++++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-17.c | 37 +++++++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-2.c | 27 ++++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-3.c | 26 ++++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-4.c | 26 ++++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-5.c | 26 ++++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-6.c | 42 ++++++++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-7.c | 40 ++++++++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-8.c | 36 +++++++++++ gcc/testsuite/gcc.dg/torture/crc-side-instr-9.c | 31 +++++++++ 44 files changed, 798 insertions(+), 798 deletions(-) delete mode 100644 gcc/testsuite/gcc.dg/crc-linux-1.c delete mode 100644 gcc/testsuite/gcc.dg/crc-linux-2.c delete mode 100644 gcc/testsuite/gcc.dg/crc-linux-4.c delete mode 100644 gcc/testsuite/gcc.dg/crc-linux-5.c delete mode 100644 gcc/testsuite/gcc.dg/crc-not-crc-15.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-1.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-10.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-11.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-12.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-13.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-14.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-15.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-16.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-17.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-2.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-3.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-4.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-5.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-6.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-7.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-8.c delete mode 100644 gcc/testsuite/gcc.dg/crc-side-instr-9.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-linux-1.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-linux-2.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-linux-4.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-linux-5.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-not-crc-15.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-1.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-10.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-11.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-12.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-13.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-14.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-15.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-16.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-17.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-2.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-3.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-4.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-5.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-6.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-7.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-8.c create mode 100644 gcc/testsuite/gcc.dg/torture/crc-side-instr-9.c (limited to 'gcc') diff --git a/gcc/testsuite/gcc.dg/crc-linux-1.c b/gcc/testsuite/gcc.dg/crc-linux-1.c deleted file mode 100644 index 918b423..0000000 --- a/gcc/testsuite/gcc.dg/crc-linux-1.c +++ /dev/null @@ -1,45 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details -w" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-O3" "-flto" } } */ - -#include -#define CRC32_POLY_BE 0x04c11db7 -#define RETVAL_OUT_OF_MEMORY (-6) -#define RETVAL_NOT_BZIP_DATA (-2) -#define RETVAL_OK 0 - -struct bunzip_data { - unsigned int crc32Table[256]; -}; - - -int start_bunzip(struct bunzip_data **bdp, void *inbuf, long len, - long (*fill)(void*, unsigned long)) -{ - if (sizeof (unsigned int) <= 3) - exit (0); - - struct bunzip_data *bd; - unsigned int i, j, c; - - /* Figure out how much data to allocate */ - i = sizeof(struct bunzip_data); - - /* Allocate bunzip_data. Most fields initialize to zero. */ - bd = *bdp = malloc(i); - - /* ... */ - - /* Init the CRC32 table (big endian) */ - for (i = 0; i < 256; i++) { - c = i << 24; - for (j = 8; j; j--) - c = c&0x80000000 ? (c << 1)^(CRC32_POLY_BE) : (c << 1); - bd->crc32Table[i] = c; - } - - /* . . . */ - return RETVAL_OK; -} - -/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-linux-2.c b/gcc/testsuite/gcc.dg/crc-linux-2.c deleted file mode 100644 index 033671c..0000000 --- a/gcc/testsuite/gcc.dg/crc-linux-2.c +++ /dev/null @@ -1,65 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -#include -typedef unsigned char u8; -typedef unsigned short u16; -typedef unsigned char __u8; -typedef unsigned short __u16; -struct i2c_msg { - __u16 addr; - __u16 flags; -#define I2C_M_RD 0x0001 /* guaranteed to be 0x0001! */ - /* ... */ - __u16 len; - __u8 *buf; -}; - -#define POLY (0x1070U << 3) -static u8 crc8(u16 data) -{ - int i; - - for (i = 0; i < 8; i++) { - if (data & 0x8000) - data = data ^ POLY; - data = data << 1; - } - return (u8)(data >> 8); -} - -/** -* i2c_smbus_pec - Incremental CRC8 over the given input data array -* @crc: previous return crc8 value -* @p: pointer to data buffer. -* @count: number of bytes in data buffer. -* -* Incremental CRC8 over count bytes in the array pointed to by p -*/ -u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count) -{ - int i; - - for (i = 0; i < count; i++) - crc = crc8((crc ^ p[i]) << 8); - return crc; -} -static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) -{ - return (msg->addr << 1) | (msg->flags & I2C_M_RD ? 1 : 0); -} - - -/* Assume a 7-bit address, which is reasonable for SMBus */ -u8 i2c_smbus_msg_pec(u8 pec, struct i2c_msg *msg) -{ - /* The address will be sent first */ - u8 addr = i2c_8bit_addr_from_msg(msg); - pec = i2c_smbus_pec(pec, &addr, 1); - - /* The data buffer follows */ - return i2c_smbus_pec(pec, msg->buf, msg->len); -} - -/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-linux-4.c b/gcc/testsuite/gcc.dg/crc-linux-4.c deleted file mode 100644 index b79dba4..0000000 --- a/gcc/testsuite/gcc.dg/crc-linux-4.c +++ /dev/null @@ -1,30 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details -w" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -/* We don't detect, it's optimized to branch-less CRC. */ -#define CRC32_POLY_LE 0xedb88320 -typedef unsigned int u32; -u32 calc_crc(unsigned char *buf, int len) -{ - u32 reg; - u32 tmp; - int j, k; - - reg = 0xffffffff; - - for (j = 0; j < len; j++) { - reg ^= buf[j]; - - for (k = 0; k < 8; k++) { - tmp = reg & 0x01; - - reg >>= 1; - - if (tmp) - reg ^= CRC32_POLY_LE; - } - } - - return ~reg; -} diff --git a/gcc/testsuite/gcc.dg/crc-linux-5.c b/gcc/testsuite/gcc.dg/crc-linux-5.c deleted file mode 100644 index ff3cc25..0000000 --- a/gcc/testsuite/gcc.dg/crc-linux-5.c +++ /dev/null @@ -1,81 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -#include -#include -/* We don't find, as we can't replace the first loop, - and in the second loop polynomials leading 1 bit is kept too - (second function's iteration count is 4). */ -typedef unsigned char u8; -typedef unsigned short u16; -u8 drm_dp_msg_data_crc4(const uint8_t *data, u8 number_of_bytes) -{ - u8 bitmask = 0x80; - u8 bitshift = 7; - u8 array_index = 0; - int number_of_bits = number_of_bytes * 8; - u16 remainder = 0; - - while (number_of_bits != 0) { - number_of_bits--; - remainder <<= 1; - remainder |= (data[array_index] & bitmask) >> bitshift; - bitmask >>= 1; - bitshift--; - if (bitmask == 0) { - bitmask = 0x80; - bitshift = 7; - array_index++; - } - if ((remainder & 0x100) == 0x100) - remainder ^= 0xd5; - } - - number_of_bits = 8; - while (number_of_bits != 0) { - number_of_bits--; - remainder <<= 1; - if ((remainder & 0x100) != 0) - remainder ^= 0xd5; - } - - return remainder & 0xff; -} - -/* sideband msg handling */ -u8 drm_dp_msg_header_crc4(const uint8_t *data, size_t num_nibbles) -{ - u8 bitmask = 0x80; - u8 bitshift = 7; - u8 array_index = 0; - int number_of_bits = num_nibbles * 4; - u8 remainder = 0; - - while (number_of_bits != 0) { - number_of_bits--; - remainder <<= 1; - remainder |= (data[array_index] & bitmask) >> bitshift; - bitmask >>= 1; - bitshift--; - if (bitmask == 0) { - bitmask = 0x80; - bitshift = 7; - array_index++; - } - if ((remainder & 0x10) == 0x10) - remainder ^= 0x13; - } - - number_of_bits = 4; - while (number_of_bits != 0) { - number_of_bits--; - remainder <<= 1; - if ((remainder & 0x10) != 0) - remainder ^= 0x13; - } - - return remainder; -} - -/* { dg-final { scan-tree-dump "drm_dp_msg_data_crc4 function maybe contains CRC calculation." "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-not-crc-15.c b/gcc/testsuite/gcc.dg/crc-not-crc-15.c deleted file mode 100644 index a8d18aa..0000000 --- a/gcc/testsuite/gcc.dg/crc-not-crc-15.c +++ /dev/null @@ -1,23 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-O3" "-flto" } } */ - -/* With -O3 the cycles is split into 2, - and one of them calculates CRC (when data != 0). - Thus, when compiling with -O3 there is CRC. */ - -#include - -uint8_t not_crc(uint8_t crc, uint8_t data) { - crc = crc ^ data; - - for (uint8_t i = 0, n = 0; i < 8; i++, n++) { - if ((crc & 0x01) && data) - crc = (crc >> 1) ^ 0x8C; - else - crc >>= 1; - } - return crc; -} - -/* { dg-final { scan-tree-dump-times "calculates CRC!" 0 "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-1.c b/gcc/testsuite/gcc.dg/crc-side-instr-1.c deleted file mode 100644 index e3c0cef..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-1.c +++ /dev/null @@ -1,27 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -#include - -uint16_t crc16_update (uint16_t crc, uint8_t a) -{ - int i; - for (i = 0; i < 8; ++i) - { - int b; - if ((crc & 1) ^ (a & 1)) - crc = (crc >> 1) ^ 0xa001; - else - crc = (crc >> 1); - a >>= 1; - b = crc; // Unused instruction, this is safe to remove. - } - return crc; -} - -/* { dg-final { scan-tree-dump "crc16_update function maybe contains CRC calculation." "crc" } } */ -/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */ -/* { dg-final { scan-tree-dump "Bit reversed" "crc" } } */ -/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ -/* { dg-final { scan-tree-dump "Polynomial's value is \\\{1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\\\}" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-10.c b/gcc/testsuite/gcc.dg/crc-side-instr-10.c deleted file mode 100644 index c770c2d..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-10.c +++ /dev/null @@ -1,31 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -typedef unsigned short ee_u16; -typedef unsigned char ee_u8; - -ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { - ee_u16 i = 0, x16 = 0, carry = 0; - int a = 1; - for (i = 0; i < 8; i++) { - x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); - data >>= 1; - if (x16 == 1) { - crc ^= 0x4002; - carry = 1; - } else - carry = 0; - crc >>= 1; - a = a * (crc + 5); - if (carry) - { - crc |= 0x8000; - } - else - crc &= 0x7fff; - } - return a; -} - -/* { dg-final { scan-tree-dump "Output CRC and determined input CRC differ." "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-11.c b/gcc/testsuite/gcc.dg/crc-side-instr-11.c deleted file mode 100644 index f32c8f9..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-11.c +++ /dev/null @@ -1,31 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -typedef unsigned short ee_u16; -typedef unsigned char ee_u8; - -ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { - ee_u16 i = 0, x16 = 0, carry = 0; - int a = 1; - for (i = 0; i < 8; i++) { - x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); - data >>= 1; - if (x16 == 1) { - crc ^= 0x4002; - carry = 1; - } else - carry = 0; - crc >>= 1; - a = a * (crc + 5); - if (carry) - { - crc |= 0x8000; - } - else - crc &= 0x7fff; - } - return a + crc; -} - -/* { dg-final { scan-tree-dump "There is more than one output phi." "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-12.c b/gcc/testsuite/gcc.dg/crc-side-instr-12.c deleted file mode 100644 index 5ea6b65..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-12.c +++ /dev/null @@ -1,33 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -typedef unsigned short ee_u16; -typedef unsigned char ee_u8; - -int a; -ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { - ee_u16 i = 0, x16 = 0, carry = 0; - int c; - for (i = 0; i < 8; i++) { - c += i*2; // In compiled code, it is moved outside of the loop. - x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); - data >>= 1; - if (x16 == 1) { - crc ^= 0x4002; - carry = 1; - } else - carry = 0; - crc >>= 1; - a = c; - if (carry) - { - crc |= 0x8000; - } - else - crc &= 0x7fff; - } - return crc; -} - -/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-13.c b/gcc/testsuite/gcc.dg/crc-side-instr-13.c deleted file mode 100644 index 810a5cd..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-13.c +++ /dev/null @@ -1,31 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -typedef unsigned short ee_u16; -typedef unsigned char ee_u8; - -int a; -ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { - ee_u16 i = 0, x16 = 0, carry = 0; - int c; - for (i = 0; i < 8; i++) { - c += crc * 2; - x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); - data >>= 1; - if (x16 == 1) { - crc ^= 0x4002; - carry = 1; - } else - carry = 0; - crc >>= 1; - a = c; - if (carry) { - crc |= 0x8000; - } else - crc &= 0x7fff; - } - return crc; -} - -/* { dg-final { scan-tree-dump "There is more than one output phi." "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-14.c b/gcc/testsuite/gcc.dg/crc-side-instr-14.c deleted file mode 100644 index 27021d1..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-14.c +++ /dev/null @@ -1,35 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -#include -typedef unsigned short ee_u16; -typedef unsigned char ee_u8; - -int a; -ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { - ee_u16 i = 0, x16 = 0, carry = 0; - int c; - for (i = 0; i < 8; i++) { - c += i*2; - printf ("%d", c); - x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); - data >>= 1; - if (x16 == 1) { - crc ^= 0x4002; - carry = 1; - } else - carry = 0; - crc >>= 1; - a = c; - if (carry) - { - crc |= 0x8000; - } - else - crc &= 0x7fff; - } - return crc; -} - -/* { dg-final { scan-tree-dump-times "calculates CRC!" 0 "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-15.c b/gcc/testsuite/gcc.dg/crc-side-instr-15.c deleted file mode 100644 index 3f33506..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-15.c +++ /dev/null @@ -1,37 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -typedef unsigned short ee_u16; -typedef unsigned char ee_u8; - -int foo (int c) -{ - return c*c; -} - -ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { - ee_u16 i = 0, x16 = 0, carry = 0; - int c; - for (i = 0; i < 8; i++) { - c += i*2; - c = foo (c); // All calculations related to c are removed. - x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); - data >>= 1; - if (x16 == 1) { - crc ^= 0x4002; - carry = 1; - } else - carry = 0; - crc >>= 1; - if (carry) - { - crc |= 0x8000; - } - else - crc &= 0x7fff; - } - return crc; -} - -/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-16.c b/gcc/testsuite/gcc.dg/crc-side-instr-16.c deleted file mode 100644 index 714c6bd..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-16.c +++ /dev/null @@ -1,38 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -typedef unsigned short ee_u16; -typedef unsigned char ee_u8; - -__attribute__ ((noinline,noipa)) -int foo (int c) -{ - return c*c; -} - -ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { - ee_u16 i = 0, x16 = 0, carry = 0; - int c; - for (i = 0; i < 8; i++) { - c += i*2; - c = foo (c); //Warning, encountered unsupported statement, while executing gimple statements! - x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); - data >>= 1; - if (x16 == 1) { - crc ^= 0x4002; - carry = 1; - } else - carry = 0; - crc >>= 1; - if (carry) - { - crc |= 0x8000; - } - else - crc &= 0x7fff; - } - return crc; -} - -/* { dg-final { scan-tree-dump-times "calculates CRC!" 0 "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-17.c b/gcc/testsuite/gcc.dg/crc-side-instr-17.c deleted file mode 100644 index 759e516..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-17.c +++ /dev/null @@ -1,37 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -typedef unsigned short ee_u16; -typedef unsigned char ee_u8; - -int foo (int c) -{ - return c*c; -} - -ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { - ee_u16 i = 0, x16 = 0, carry = 0; - int c; - for (i = 0; i < 8; i++) { - c += i*2; - c = foo (c); - x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); - data >>= 1; - if (x16 == 1) { - crc ^= 0x4002; - carry = 1; - } else - carry = 0; - crc >>= 1; - if (carry) - { - crc |= 0x8000; - } - else - crc &= 0x7fff; - } - return crc + c; -} - -/* { dg-final { scan-tree-dump "There is more than one output phi." "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-2.c b/gcc/testsuite/gcc.dg/crc-side-instr-2.c deleted file mode 100644 index 758ec10..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-2.c +++ /dev/null @@ -1,27 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -#include -#include - -uint16_t crc16_update(uint16_t crc, uint8_t a) { - int i; - int b; - for (i = 0; i < 8; ++i) { - if ((crc & 1) ^ (a & 1)) - crc = (crc >> 1) ^ 0xa001; - else - crc = (crc >> 1); - a >>= 1; - b = crc; // Unused instruction, this is safe to remove. - } - printf ("%d", b); - return crc; -} - -/* { dg-final { scan-tree-dump "crc16_update function maybe contains CRC calculation." "crc" } } */ -/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */ -/* { dg-final { scan-tree-dump "Bit reversed" "crc" } } */ -/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ -/* { dg-final { scan-tree-dump "Polynomial's value is \\\{1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\\\}" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-3.c b/gcc/testsuite/gcc.dg/crc-side-instr-3.c deleted file mode 100644 index 9c56754..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-3.c +++ /dev/null @@ -1,26 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -#include - -uint16_t crc16_update(uint16_t crc, uint8_t a) { - int i; - int b; - for (i = 0; i < 8; ++i) { - if ((crc & 1) ^ (a & 1)) - crc = (crc >> 1) ^ 0xa001; - else - crc = (crc >> 1); - a >>= 1; - b = crc; - } - int c = b; // This is removed from the compiled code. - return crc; -} - -/* { dg-final { scan-tree-dump "crc16_update function maybe contains CRC calculation." "crc" } } */ -/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */ -/* { dg-final { scan-tree-dump "Bit reversed" "crc" } } */ -/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ -/* { dg-final { scan-tree-dump "Polynomial's value is \\\{1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\\\}" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-4.c b/gcc/testsuite/gcc.dg/crc-side-instr-4.c deleted file mode 100644 index 15dbd27..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-4.c +++ /dev/null @@ -1,26 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -#include - -uint16_t crc16_update(uint16_t crc, uint8_t a) { - int i; - uint16_t b; - for (i = 0; i < 8; ++i) { - if ((crc & 1) ^ (a & 1)) - crc = (crc >> 1) ^ 0xa001; - else - crc = (crc >> 1); - a >>= 1; - b = crc; - } - uint16_t c = b++; // This is removed from the compiled code. - return crc; -} - -/* { dg-final { scan-tree-dump "crc16_update function maybe contains CRC calculation." "crc" } } */ -/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */ -/* { dg-final { scan-tree-dump "Bit reversed" "crc" } } */ -/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ -/* { dg-final { scan-tree-dump "Polynomial's value is \\\{1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\\\}" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-5.c b/gcc/testsuite/gcc.dg/crc-side-instr-5.c deleted file mode 100644 index 0af1adf..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-5.c +++ /dev/null @@ -1,26 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -#include - -uint16_t crc16_update(uint16_t crc, uint8_t a) { - int i; - uint16_t b; - for (i = 0; i < 8; ++i) { - if ((crc & 1) ^ (a & 1)) - crc = (crc >> 1) ^ 0xa001; - else - crc = (crc >> 1); - a >>= 1; - b = crc; // In compiled version, b is outside of the loop. - } - uint16_t c = ++b; - return c; -} - -/* { dg-final { scan-tree-dump "crc16_update function maybe contains CRC calculation." "crc" } } */ -/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */ -/* { dg-final { scan-tree-dump "Bit reversed" "crc" } } */ -/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ -/* { dg-final { scan-tree-dump "Polynomial's value is \\\{1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\\\}" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-6.c b/gcc/testsuite/gcc.dg/crc-side-instr-6.c deleted file mode 100644 index 9423d75..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-6.c +++ /dev/null @@ -1,42 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -#include -#include -typedef unsigned short ee_u16; -typedef unsigned char ee_u8; - -int a; -ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { - ee_u8 i = 0, x16 = 0, carry = 0; - for (i = 0; i < 8; i++) { - a++; // this is moved outside of the loop - x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); - data >>= 1; - if (x16 == 1) { - crc ^= 0x4002; - carry = 1; - } else - carry = 0; - crc >>= 1; - if (carry) - crc |= 0x8000; - else - crc &= 0x7fff; - } - return crc; -} - -int main() -{ - printf ("%04X\n", crcu8 (0, 0xaa)); - printf ("%d", a); -} - - -/* { dg-final { scan-tree-dump "crcu8 function maybe contains CRC calculation." "crc" } } */ -/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */ -/* { dg-final { scan-tree-dump "Bit reversed" "crc" } } */ -/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ -/* { dg-final { scan-tree-dump "Polynomial's value is \\\{\[0, \]*1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\\\}" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-7.c b/gcc/testsuite/gcc.dg/crc-side-instr-7.c deleted file mode 100644 index ce8f8a8..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-7.c +++ /dev/null @@ -1,40 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -#include -typedef unsigned short ee_u16; -typedef unsigned char ee_u8; - -int a[10] = {}; -ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { - ee_u8 i = 0, x16 = 0, carry = 0; - for (i = 0; i < 8; i++) { - a[i] = crc; - x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); - data >>= 1; - if (x16 == 1) { - crc ^= 0x4002; - carry = 1; - } else - carry = 0; - crc >>= 1; - if (carry) - crc |= 0x8000; - else - crc &= 0x7fff; - } - return crc; -} - -int main() -{ - printf ("%04X\n", crcu8 (0, 0xaa)); - printf ("%d", a[0]); -} - - -/* { dg-final { scan-tree-dump "crcu8 function maybe contains CRC calculation." "crc" } } */ -/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */ -/* { dg-final { scan-tree-dump "Bit reversed" "crc" } } */ -/* { dg-final { scan-tree-dump-times "calculates CRC!" 0 "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-8.c b/gcc/testsuite/gcc.dg/crc-side-instr-8.c deleted file mode 100644 index 037e811..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-8.c +++ /dev/null @@ -1,36 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -#include -typedef unsigned short ee_u16; -typedef unsigned char ee_u8; - -int a; -ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { - ee_u8 i = 0, x16 = 0, carry = 0; - for (i = 0; i < 8; i++) { - a += crc; // Defined variable is used outside the loop. - x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); - data >>= 1; - if (x16 == 1) { - crc ^= 0x4002; - carry = 1; - } else - carry = 0; - crc >>= 1; - if (carry) - crc |= 0x8000; - else - crc &= 0x7fff; - } - return crc; -} - -int main() -{ - printf ("%04X\n", crcu8 (0, 0xaa)); - printf ("%d", a); -} - -/* { dg-final { scan-tree-dump "There is more than one output phi." "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/crc-side-instr-9.c b/gcc/testsuite/gcc.dg/crc-side-instr-9.c deleted file mode 100644 index af0258e..0000000 --- a/gcc/testsuite/gcc.dg/crc-side-instr-9.c +++ /dev/null @@ -1,31 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fdump-tree-crc-details" } */ -/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ - -typedef unsigned short ee_u16; -typedef unsigned char ee_u8; - -int a; -ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { - ee_u8 i = 0, x16 = 0, carry = 0; - for (i = 0; i < 8; i++) { - x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); - data >>= 1; - if (x16 == 1) { - crc ^= 0x4002; - carry = 1; - } else - carry = 0; - crc >>= 1; - if (carry) - { - a = crc; - crc |= 0x8000; - } - else - crc &= 0x7fff; - } - return crc; -} - -/* { dg-final { scan-tree-dump "There is more than one output phi." "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-linux-1.c b/gcc/testsuite/gcc.dg/torture/crc-linux-1.c new file mode 100644 index 0000000..918b423 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-linux-1.c @@ -0,0 +1,45 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details -w" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-O3" "-flto" } } */ + +#include +#define CRC32_POLY_BE 0x04c11db7 +#define RETVAL_OUT_OF_MEMORY (-6) +#define RETVAL_NOT_BZIP_DATA (-2) +#define RETVAL_OK 0 + +struct bunzip_data { + unsigned int crc32Table[256]; +}; + + +int start_bunzip(struct bunzip_data **bdp, void *inbuf, long len, + long (*fill)(void*, unsigned long)) +{ + if (sizeof (unsigned int) <= 3) + exit (0); + + struct bunzip_data *bd; + unsigned int i, j, c; + + /* Figure out how much data to allocate */ + i = sizeof(struct bunzip_data); + + /* Allocate bunzip_data. Most fields initialize to zero. */ + bd = *bdp = malloc(i); + + /* ... */ + + /* Init the CRC32 table (big endian) */ + for (i = 0; i < 256; i++) { + c = i << 24; + for (j = 8; j; j--) + c = c&0x80000000 ? (c << 1)^(CRC32_POLY_BE) : (c << 1); + bd->crc32Table[i] = c; + } + + /* . . . */ + return RETVAL_OK; +} + +/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-linux-2.c b/gcc/testsuite/gcc.dg/torture/crc-linux-2.c new file mode 100644 index 0000000..033671c --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-linux-2.c @@ -0,0 +1,65 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +#include +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned char __u8; +typedef unsigned short __u16; +struct i2c_msg { + __u16 addr; + __u16 flags; +#define I2C_M_RD 0x0001 /* guaranteed to be 0x0001! */ + /* ... */ + __u16 len; + __u8 *buf; +}; + +#define POLY (0x1070U << 3) +static u8 crc8(u16 data) +{ + int i; + + for (i = 0; i < 8; i++) { + if (data & 0x8000) + data = data ^ POLY; + data = data << 1; + } + return (u8)(data >> 8); +} + +/** +* i2c_smbus_pec - Incremental CRC8 over the given input data array +* @crc: previous return crc8 value +* @p: pointer to data buffer. +* @count: number of bytes in data buffer. +* +* Incremental CRC8 over count bytes in the array pointed to by p +*/ +u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count) +{ + int i; + + for (i = 0; i < count; i++) + crc = crc8((crc ^ p[i]) << 8); + return crc; +} +static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) +{ + return (msg->addr << 1) | (msg->flags & I2C_M_RD ? 1 : 0); +} + + +/* Assume a 7-bit address, which is reasonable for SMBus */ +u8 i2c_smbus_msg_pec(u8 pec, struct i2c_msg *msg) +{ + /* The address will be sent first */ + u8 addr = i2c_8bit_addr_from_msg(msg); + pec = i2c_smbus_pec(pec, &addr, 1); + + /* The data buffer follows */ + return i2c_smbus_pec(pec, msg->buf, msg->len); +} + +/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-linux-4.c b/gcc/testsuite/gcc.dg/torture/crc-linux-4.c new file mode 100644 index 0000000..b79dba4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-linux-4.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details -w" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +/* We don't detect, it's optimized to branch-less CRC. */ +#define CRC32_POLY_LE 0xedb88320 +typedef unsigned int u32; +u32 calc_crc(unsigned char *buf, int len) +{ + u32 reg; + u32 tmp; + int j, k; + + reg = 0xffffffff; + + for (j = 0; j < len; j++) { + reg ^= buf[j]; + + for (k = 0; k < 8; k++) { + tmp = reg & 0x01; + + reg >>= 1; + + if (tmp) + reg ^= CRC32_POLY_LE; + } + } + + return ~reg; +} diff --git a/gcc/testsuite/gcc.dg/torture/crc-linux-5.c b/gcc/testsuite/gcc.dg/torture/crc-linux-5.c new file mode 100644 index 0000000..ff3cc25 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-linux-5.c @@ -0,0 +1,81 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +#include +#include +/* We don't find, as we can't replace the first loop, + and in the second loop polynomials leading 1 bit is kept too + (second function's iteration count is 4). */ +typedef unsigned char u8; +typedef unsigned short u16; +u8 drm_dp_msg_data_crc4(const uint8_t *data, u8 number_of_bytes) +{ + u8 bitmask = 0x80; + u8 bitshift = 7; + u8 array_index = 0; + int number_of_bits = number_of_bytes * 8; + u16 remainder = 0; + + while (number_of_bits != 0) { + number_of_bits--; + remainder <<= 1; + remainder |= (data[array_index] & bitmask) >> bitshift; + bitmask >>= 1; + bitshift--; + if (bitmask == 0) { + bitmask = 0x80; + bitshift = 7; + array_index++; + } + if ((remainder & 0x100) == 0x100) + remainder ^= 0xd5; + } + + number_of_bits = 8; + while (number_of_bits != 0) { + number_of_bits--; + remainder <<= 1; + if ((remainder & 0x100) != 0) + remainder ^= 0xd5; + } + + return remainder & 0xff; +} + +/* sideband msg handling */ +u8 drm_dp_msg_header_crc4(const uint8_t *data, size_t num_nibbles) +{ + u8 bitmask = 0x80; + u8 bitshift = 7; + u8 array_index = 0; + int number_of_bits = num_nibbles * 4; + u8 remainder = 0; + + while (number_of_bits != 0) { + number_of_bits--; + remainder <<= 1; + remainder |= (data[array_index] & bitmask) >> bitshift; + bitmask >>= 1; + bitshift--; + if (bitmask == 0) { + bitmask = 0x80; + bitshift = 7; + array_index++; + } + if ((remainder & 0x10) == 0x10) + remainder ^= 0x13; + } + + number_of_bits = 4; + while (number_of_bits != 0) { + number_of_bits--; + remainder <<= 1; + if ((remainder & 0x10) != 0) + remainder ^= 0x13; + } + + return remainder; +} + +/* { dg-final { scan-tree-dump "drm_dp_msg_data_crc4 function maybe contains CRC calculation." "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-not-crc-15.c b/gcc/testsuite/gcc.dg/torture/crc-not-crc-15.c new file mode 100644 index 0000000..a8d18aa --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-not-crc-15.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-O3" "-flto" } } */ + +/* With -O3 the cycles is split into 2, + and one of them calculates CRC (when data != 0). + Thus, when compiling with -O3 there is CRC. */ + +#include + +uint8_t not_crc(uint8_t crc, uint8_t data) { + crc = crc ^ data; + + for (uint8_t i = 0, n = 0; i < 8; i++, n++) { + if ((crc & 0x01) && data) + crc = (crc >> 1) ^ 0x8C; + else + crc >>= 1; + } + return crc; +} + +/* { dg-final { scan-tree-dump-times "calculates CRC!" 0 "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-1.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-1.c new file mode 100644 index 0000000..e3c0cef --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-1.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +#include + +uint16_t crc16_update (uint16_t crc, uint8_t a) +{ + int i; + for (i = 0; i < 8; ++i) + { + int b; + if ((crc & 1) ^ (a & 1)) + crc = (crc >> 1) ^ 0xa001; + else + crc = (crc >> 1); + a >>= 1; + b = crc; // Unused instruction, this is safe to remove. + } + return crc; +} + +/* { dg-final { scan-tree-dump "crc16_update function maybe contains CRC calculation." "crc" } } */ +/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */ +/* { dg-final { scan-tree-dump "Bit reversed" "crc" } } */ +/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ +/* { dg-final { scan-tree-dump "Polynomial's value is \\\{1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\\\}" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-10.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-10.c new file mode 100644 index 0000000..c770c2d --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-10.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +typedef unsigned short ee_u16; +typedef unsigned char ee_u8; + +ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { + ee_u16 i = 0, x16 = 0, carry = 0; + int a = 1; + for (i = 0; i < 8; i++) { + x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); + data >>= 1; + if (x16 == 1) { + crc ^= 0x4002; + carry = 1; + } else + carry = 0; + crc >>= 1; + a = a * (crc + 5); + if (carry) + { + crc |= 0x8000; + } + else + crc &= 0x7fff; + } + return a; +} + +/* { dg-final { scan-tree-dump "Output CRC and determined input CRC differ." "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-11.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-11.c new file mode 100644 index 0000000..f32c8f9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-11.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +typedef unsigned short ee_u16; +typedef unsigned char ee_u8; + +ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { + ee_u16 i = 0, x16 = 0, carry = 0; + int a = 1; + for (i = 0; i < 8; i++) { + x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); + data >>= 1; + if (x16 == 1) { + crc ^= 0x4002; + carry = 1; + } else + carry = 0; + crc >>= 1; + a = a * (crc + 5); + if (carry) + { + crc |= 0x8000; + } + else + crc &= 0x7fff; + } + return a + crc; +} + +/* { dg-final { scan-tree-dump "There is more than one output phi." "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-12.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-12.c new file mode 100644 index 0000000..5ea6b65 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-12.c @@ -0,0 +1,33 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +typedef unsigned short ee_u16; +typedef unsigned char ee_u8; + +int a; +ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { + ee_u16 i = 0, x16 = 0, carry = 0; + int c; + for (i = 0; i < 8; i++) { + c += i*2; // In compiled code, it is moved outside of the loop. + x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); + data >>= 1; + if (x16 == 1) { + crc ^= 0x4002; + carry = 1; + } else + carry = 0; + crc >>= 1; + a = c; + if (carry) + { + crc |= 0x8000; + } + else + crc &= 0x7fff; + } + return crc; +} + +/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-13.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-13.c new file mode 100644 index 0000000..810a5cd --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-13.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +typedef unsigned short ee_u16; +typedef unsigned char ee_u8; + +int a; +ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { + ee_u16 i = 0, x16 = 0, carry = 0; + int c; + for (i = 0; i < 8; i++) { + c += crc * 2; + x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); + data >>= 1; + if (x16 == 1) { + crc ^= 0x4002; + carry = 1; + } else + carry = 0; + crc >>= 1; + a = c; + if (carry) { + crc |= 0x8000; + } else + crc &= 0x7fff; + } + return crc; +} + +/* { dg-final { scan-tree-dump "There is more than one output phi." "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-14.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-14.c new file mode 100644 index 0000000..27021d1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-14.c @@ -0,0 +1,35 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +#include +typedef unsigned short ee_u16; +typedef unsigned char ee_u8; + +int a; +ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { + ee_u16 i = 0, x16 = 0, carry = 0; + int c; + for (i = 0; i < 8; i++) { + c += i*2; + printf ("%d", c); + x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); + data >>= 1; + if (x16 == 1) { + crc ^= 0x4002; + carry = 1; + } else + carry = 0; + crc >>= 1; + a = c; + if (carry) + { + crc |= 0x8000; + } + else + crc &= 0x7fff; + } + return crc; +} + +/* { dg-final { scan-tree-dump-times "calculates CRC!" 0 "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-15.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-15.c new file mode 100644 index 0000000..3f33506 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-15.c @@ -0,0 +1,37 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +typedef unsigned short ee_u16; +typedef unsigned char ee_u8; + +int foo (int c) +{ + return c*c; +} + +ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { + ee_u16 i = 0, x16 = 0, carry = 0; + int c; + for (i = 0; i < 8; i++) { + c += i*2; + c = foo (c); // All calculations related to c are removed. + x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); + data >>= 1; + if (x16 == 1) { + crc ^= 0x4002; + carry = 1; + } else + carry = 0; + crc >>= 1; + if (carry) + { + crc |= 0x8000; + } + else + crc &= 0x7fff; + } + return crc; +} + +/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-16.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-16.c new file mode 100644 index 0000000..714c6bd --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-16.c @@ -0,0 +1,38 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +typedef unsigned short ee_u16; +typedef unsigned char ee_u8; + +__attribute__ ((noinline,noipa)) +int foo (int c) +{ + return c*c; +} + +ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { + ee_u16 i = 0, x16 = 0, carry = 0; + int c; + for (i = 0; i < 8; i++) { + c += i*2; + c = foo (c); //Warning, encountered unsupported statement, while executing gimple statements! + x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); + data >>= 1; + if (x16 == 1) { + crc ^= 0x4002; + carry = 1; + } else + carry = 0; + crc >>= 1; + if (carry) + { + crc |= 0x8000; + } + else + crc &= 0x7fff; + } + return crc; +} + +/* { dg-final { scan-tree-dump-times "calculates CRC!" 0 "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-17.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-17.c new file mode 100644 index 0000000..759e516 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-17.c @@ -0,0 +1,37 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +typedef unsigned short ee_u16; +typedef unsigned char ee_u8; + +int foo (int c) +{ + return c*c; +} + +ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { + ee_u16 i = 0, x16 = 0, carry = 0; + int c; + for (i = 0; i < 8; i++) { + c += i*2; + c = foo (c); + x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); + data >>= 1; + if (x16 == 1) { + crc ^= 0x4002; + carry = 1; + } else + carry = 0; + crc >>= 1; + if (carry) + { + crc |= 0x8000; + } + else + crc &= 0x7fff; + } + return crc + c; +} + +/* { dg-final { scan-tree-dump "There is more than one output phi." "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-2.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-2.c new file mode 100644 index 0000000..758ec10 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-2.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +#include +#include + +uint16_t crc16_update(uint16_t crc, uint8_t a) { + int i; + int b; + for (i = 0; i < 8; ++i) { + if ((crc & 1) ^ (a & 1)) + crc = (crc >> 1) ^ 0xa001; + else + crc = (crc >> 1); + a >>= 1; + b = crc; // Unused instruction, this is safe to remove. + } + printf ("%d", b); + return crc; +} + +/* { dg-final { scan-tree-dump "crc16_update function maybe contains CRC calculation." "crc" } } */ +/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */ +/* { dg-final { scan-tree-dump "Bit reversed" "crc" } } */ +/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ +/* { dg-final { scan-tree-dump "Polynomial's value is \\\{1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\\\}" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-3.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-3.c new file mode 100644 index 0000000..9c56754 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-3.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +#include + +uint16_t crc16_update(uint16_t crc, uint8_t a) { + int i; + int b; + for (i = 0; i < 8; ++i) { + if ((crc & 1) ^ (a & 1)) + crc = (crc >> 1) ^ 0xa001; + else + crc = (crc >> 1); + a >>= 1; + b = crc; + } + int c = b; // This is removed from the compiled code. + return crc; +} + +/* { dg-final { scan-tree-dump "crc16_update function maybe contains CRC calculation." "crc" } } */ +/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */ +/* { dg-final { scan-tree-dump "Bit reversed" "crc" } } */ +/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ +/* { dg-final { scan-tree-dump "Polynomial's value is \\\{1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\\\}" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-4.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-4.c new file mode 100644 index 0000000..15dbd27 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-4.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +#include + +uint16_t crc16_update(uint16_t crc, uint8_t a) { + int i; + uint16_t b; + for (i = 0; i < 8; ++i) { + if ((crc & 1) ^ (a & 1)) + crc = (crc >> 1) ^ 0xa001; + else + crc = (crc >> 1); + a >>= 1; + b = crc; + } + uint16_t c = b++; // This is removed from the compiled code. + return crc; +} + +/* { dg-final { scan-tree-dump "crc16_update function maybe contains CRC calculation." "crc" } } */ +/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */ +/* { dg-final { scan-tree-dump "Bit reversed" "crc" } } */ +/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ +/* { dg-final { scan-tree-dump "Polynomial's value is \\\{1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\\\}" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-5.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-5.c new file mode 100644 index 0000000..0af1adf --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-5.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +#include + +uint16_t crc16_update(uint16_t crc, uint8_t a) { + int i; + uint16_t b; + for (i = 0; i < 8; ++i) { + if ((crc & 1) ^ (a & 1)) + crc = (crc >> 1) ^ 0xa001; + else + crc = (crc >> 1); + a >>= 1; + b = crc; // In compiled version, b is outside of the loop. + } + uint16_t c = ++b; + return c; +} + +/* { dg-final { scan-tree-dump "crc16_update function maybe contains CRC calculation." "crc" } } */ +/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */ +/* { dg-final { scan-tree-dump "Bit reversed" "crc" } } */ +/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ +/* { dg-final { scan-tree-dump "Polynomial's value is \\\{1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\\\}" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-6.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-6.c new file mode 100644 index 0000000..9423d75 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-6.c @@ -0,0 +1,42 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +#include +#include +typedef unsigned short ee_u16; +typedef unsigned char ee_u8; + +int a; +ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { + ee_u8 i = 0, x16 = 0, carry = 0; + for (i = 0; i < 8; i++) { + a++; // this is moved outside of the loop + x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); + data >>= 1; + if (x16 == 1) { + crc ^= 0x4002; + carry = 1; + } else + carry = 0; + crc >>= 1; + if (carry) + crc |= 0x8000; + else + crc &= 0x7fff; + } + return crc; +} + +int main() +{ + printf ("%04X\n", crcu8 (0, 0xaa)); + printf ("%d", a); +} + + +/* { dg-final { scan-tree-dump "crcu8 function maybe contains CRC calculation." "crc" } } */ +/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */ +/* { dg-final { scan-tree-dump "Bit reversed" "crc" } } */ +/* { dg-final { scan-tree-dump "calculates CRC!" "crc" } } */ +/* { dg-final { scan-tree-dump "Polynomial's value is \\\{\[0, \]*1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\\\}" "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-7.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-7.c new file mode 100644 index 0000000..ce8f8a8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-7.c @@ -0,0 +1,40 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +#include +typedef unsigned short ee_u16; +typedef unsigned char ee_u8; + +int a[10] = {}; +ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { + ee_u8 i = 0, x16 = 0, carry = 0; + for (i = 0; i < 8; i++) { + a[i] = crc; + x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); + data >>= 1; + if (x16 == 1) { + crc ^= 0x4002; + carry = 1; + } else + carry = 0; + crc >>= 1; + if (carry) + crc |= 0x8000; + else + crc &= 0x7fff; + } + return crc; +} + +int main() +{ + printf ("%04X\n", crcu8 (0, 0xaa)); + printf ("%d", a[0]); +} + + +/* { dg-final { scan-tree-dump "crcu8 function maybe contains CRC calculation." "crc" } } */ +/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc" } } */ +/* { dg-final { scan-tree-dump "Bit reversed" "crc" } } */ +/* { dg-final { scan-tree-dump-times "calculates CRC!" 0 "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-8.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-8.c new file mode 100644 index 0000000..037e811 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-8.c @@ -0,0 +1,36 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +#include +typedef unsigned short ee_u16; +typedef unsigned char ee_u8; + +int a; +ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { + ee_u8 i = 0, x16 = 0, carry = 0; + for (i = 0; i < 8; i++) { + a += crc; // Defined variable is used outside the loop. + x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); + data >>= 1; + if (x16 == 1) { + crc ^= 0x4002; + carry = 1; + } else + carry = 0; + crc >>= 1; + if (carry) + crc |= 0x8000; + else + crc &= 0x7fff; + } + return crc; +} + +int main() +{ + printf ("%04X\n", crcu8 (0, 0xaa)); + printf ("%d", a); +} + +/* { dg-final { scan-tree-dump "There is more than one output phi." "crc" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/crc-side-instr-9.c b/gcc/testsuite/gcc.dg/torture/crc-side-instr-9.c new file mode 100644 index 0000000..af0258e --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/crc-side-instr-9.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-crc-details" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ + +typedef unsigned short ee_u16; +typedef unsigned char ee_u8; + +int a; +ee_u16 crcu8 (ee_u8 data, ee_u16 crc) { + ee_u8 i = 0, x16 = 0, carry = 0; + for (i = 0; i < 8; i++) { + x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); + data >>= 1; + if (x16 == 1) { + crc ^= 0x4002; + carry = 1; + } else + carry = 0; + crc >>= 1; + if (carry) + { + a = crc; + crc |= 0x8000; + } + else + crc &= 0x7fff; + } + return crc; +} + +/* { dg-final { scan-tree-dump "There is more than one output phi." "crc" } } */ -- cgit v1.1