diff options
Diffstat (limited to 'validation')
100 files changed, 2242 insertions, 227 deletions
diff --git a/validation/cast-kinds-check.c b/validation/cast-kinds-check.c index 0fe705f5..7eb1ca1c 100644 --- a/validation/cast-kinds-check.c +++ b/validation/cast-kinds-check.c @@ -1,19 +1,19 @@ -#include "linear/cast-kinds.c" +#include "optim/cast-kinds.c" /* * check-name: cast-kinds check * check-command: sparse -m64 -v -Wno-pointer-to-int-cast $file * * check-error-start -linear/cast-kinds.c:5:45: warning: cast drops bits -linear/cast-kinds.c:6:47: warning: cast drops bits -linear/cast-kinds.c:7:46: warning: cast drops bits -linear/cast-kinds.c:8:45: warning: cast drops bits -linear/cast-kinds.c:12:48: warning: cast drops bits -linear/cast-kinds.c:13:50: warning: cast drops bits -linear/cast-kinds.c:14:49: warning: cast drops bits -linear/cast-kinds.c:15:48: warning: cast drops bits -linear/cast-kinds.c:37:42: warning: non size-preserving integer to pointer cast -linear/cast-kinds.c:38:44: warning: non size-preserving integer to pointer cast +optim/cast-kinds.c:5:45: warning: cast drops bits +optim/cast-kinds.c:6:47: warning: cast drops bits +optim/cast-kinds.c:7:46: warning: cast drops bits +optim/cast-kinds.c:8:45: warning: cast drops bits +optim/cast-kinds.c:12:48: warning: cast drops bits +optim/cast-kinds.c:13:50: warning: cast drops bits +optim/cast-kinds.c:14:49: warning: cast drops bits +optim/cast-kinds.c:15:48: warning: cast drops bits +optim/cast-kinds.c:37:48: warning: non size-preserving integer to pointer cast +optim/cast-kinds.c:38:50: warning: non size-preserving integer to pointer cast * check-error-end */ diff --git a/validation/cast-weirds.c b/validation/cast-weirds.c index a99c65d2..7d028882 100644 --- a/validation/cast-weirds.c +++ b/validation/cast-weirds.c @@ -9,43 +9,10 @@ static void * uint_2_vptr(uint a) { return (void *)a; } /* * check-name: cast-weirds - * check-command: test-linearize -m64 $file + * check-command: sparse -m64 $file * * check-error-start -cast-weirds.c:4:42: warning: non size-preserving integer to pointer cast -cast-weirds.c:5:44: warning: non size-preserving integer to pointer cast +cast-weirds.c:4:48: warning: non size-preserving integer to pointer cast +cast-weirds.c:5:50: warning: non size-preserving integer to pointer cast * check-error-end - * - * check-output-start -int_2_iptr: -.L0: - <entry-point> - sext.64 %r2 <- (32) %arg1 - utptr.64 %r3 <- (64) %r2 - ret.64 %r3 - - -uint_2_iptr: -.L2: - <entry-point> - zext.64 %r6 <- (32) %arg1 - utptr.64 %r7 <- (64) %r6 - ret.64 %r7 - - -int_2_vptr: -.L4: - <entry-point> - sext.64 %r10 <- (32) %arg1 - ret.64 %r10 - - -uint_2_vptr: -.L6: - <entry-point> - zext.64 %r13 <- (32) %arg1 - ret.64 %r13 - - - * check-output-end */ diff --git a/validation/check_access-store.c b/validation/check_access-store.c new file mode 100644 index 00000000..489507fd --- /dev/null +++ b/validation/check_access-store.c @@ -0,0 +1,21 @@ +extern int a[1]; + +static int r(void) +{ + return a[1]; +} + +static void w(void) +{ + a[1] = 2; +} + +/* + * check-name: check_access-store + * check-known-to-fail + * + * check-error-start +check_access-store.c:5:17: warning: invalid access past the end of 'a' (4 4) +check_access-store.c:10:17: warning: invalid access past the end of 'a' (4 4) + * check-error-end + */ diff --git a/validation/eval-typeof-vla.c b/validation/eval-typeof-vla.c new file mode 100644 index 00000000..56a9ec20 --- /dev/null +++ b/validation/eval-typeof-vla.c @@ -0,0 +1,26 @@ +extern int a[1]; + +static int foo(int n) +{ + int i = 0; + int (*p)[1] = (typeof(++i, (int (*)[n])a)) &a; + + (void) p; + + return i; +} + +/* + * check-name: eval-typeof-vla + * check-command: test-linearize -Wno-vla $file + * check-known-to-fail + * + * check-output-start +foo: +.L0: + <entry-point> + ret.32 $1 + + + * check-output-end + */ diff --git a/validation/fp-ops.c b/validation/fp-ops.c index 81f73384..96c246f8 100644 --- a/validation/fp-ops.c +++ b/validation/fp-ops.c @@ -48,7 +48,7 @@ fneg: ftst: .L10: <entry-point> - setfval.64 %r21 <- 0.000000 + setfval.64 %r21 <- 0.000000e+00 fcmpoeq.1 %r23 <- %arg1, %r21 ret.1 %r23 diff --git a/validation/kill-switch.c b/validation/kill-switch.c new file mode 100644 index 00000000..1316a775 --- /dev/null +++ b/validation/kill-switch.c @@ -0,0 +1,17 @@ +extern int i; + +static void foo(void) +{ + switch (i) { + case 0: + ; + } +} + +/* + * check-name: kill-switch + * check-command: test-linearize $file + * + * check-output-ignore + * check-output-excludes: load\\. + */ diff --git a/validation/linear/bitfield-inc.c b/validation/linear/bitfield-inc.c new file mode 100644 index 00000000..56997592 --- /dev/null +++ b/validation/linear/bitfield-inc.c @@ -0,0 +1,16 @@ +struct s { + int f:5; +}; + +void inc(struct s *p) +{ + p->f++; +} + +/* + * check-name: bitfield-inc + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: add\\.5 + */ diff --git a/validation/linear/bitfield-preinc.c b/validation/linear/bitfield-preinc.c new file mode 100644 index 00000000..783327ae --- /dev/null +++ b/validation/linear/bitfield-preinc.c @@ -0,0 +1,18 @@ +struct s { + int f:3; +}; + +int preinc(void) +{ + struct s s = { 7 }; + return ++s.f; +} + +/* + * check-name: bitfield-preinc + * check-description: ++X is equivalent to X+=1 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: ret.32 *\\$0 + */ diff --git a/validation/linear/bitfield-size.c b/validation/linear/bitfield-size.c index 963f6e28..841bdd0a 100644 --- a/validation/linear/bitfield-size.c +++ b/validation/linear/bitfield-size.c @@ -49,41 +49,45 @@ upostinc: load.64 %r1 <- 0[x] load.32 %r2 <- 0[%r1] trunc.3 %r3 <- (32) %r2 - add.3 %r4 <- %r3, $1 - load.32 %r5 <- 0[%r1] - zext.32 %r6 <- (3) %r4 - and.32 %r7 <- %r5, $-8 - or.32 %r8 <- %r7, %r6 - store.32 %r8 -> 0[%r1] - zext.32 %r9 <- (3) %r3 - phisrc.32 %phi1(return) <- %r9 + zext.32 %r4 <- (3) %r3 + add.32 %r5 <- %r4, $1 + trunc.3 %r6 <- (32) %r5 + load.32 %r7 <- 0[%r1] + zext.32 %r8 <- (3) %r6 + and.32 %r9 <- %r7, $0xfffffff8 + or.32 %r10 <- %r9, %r8 + store.32 %r10 -> 0[%r1] + zext.32 %r11 <- (3) %r4 + phisrc.32 %phi1(return) <- %r11 br .L1 .L1: - phi.32 %r10 <- %phi1(return) - ret.32 %r10 + phi.32 %r12 <- %phi1(return) + ret.32 %r12 upreinc: .L2: <entry-point> store.64 %arg1 -> 0[x] - load.64 %r11 <- 0[x] - load.32 %r12 <- 0[%r11] - trunc.3 %r13 <- (32) %r12 - add.3 %r14 <- %r13, $1 - load.32 %r15 <- 0[%r11] - zext.32 %r16 <- (3) %r14 - and.32 %r17 <- %r15, $-8 - or.32 %r18 <- %r17, %r16 - store.32 %r18 -> 0[%r11] - zext.32 %r19 <- (3) %r14 - phisrc.32 %phi2(return) <- %r19 + load.64 %r13 <- 0[x] + load.32 %r14 <- 0[%r13] + trunc.3 %r15 <- (32) %r14 + zext.32 %r16 <- (3) %r15 + add.32 %r17 <- %r16, $1 + trunc.3 %r18 <- (32) %r17 + load.32 %r19 <- 0[%r13] + zext.32 %r20 <- (3) %r18 + and.32 %r21 <- %r19, $0xfffffff8 + or.32 %r22 <- %r21, %r20 + store.32 %r22 -> 0[%r13] + zext.32 %r23 <- (3) %r18 + phisrc.32 %phi2(return) <- %r23 br .L3 .L3: - phi.32 %r20 <- %phi2(return) - ret.32 %r20 + phi.32 %r24 <- %phi2(return) + ret.32 %r24 ucpy: @@ -91,15 +95,15 @@ ucpy: <entry-point> store.64 %arg1 -> 0[d] store.64 %arg2 -> 0[s] - load.64 %r21 <- 0[s] - load.32 %r22 <- 0[%r21] - trunc.3 %r23 <- (32) %r22 - load.64 %r24 <- 0[d] - load.32 %r25 <- 0[%r24] - zext.32 %r26 <- (3) %r23 - and.32 %r27 <- %r25, $-8 - or.32 %r28 <- %r27, %r26 - store.32 %r28 -> 0[%r24] + load.64 %r25 <- 0[s] + load.32 %r26 <- 0[%r25] + trunc.3 %r27 <- (32) %r26 + load.64 %r28 <- 0[d] + load.32 %r29 <- 0[%r28] + zext.32 %r30 <- (3) %r27 + and.32 %r31 <- %r29, $0xfffffff8 + or.32 %r32 <- %r31, %r30 + store.32 %r32 -> 0[%r28] br .L5 .L5: @@ -110,44 +114,48 @@ spostinc: .L6: <entry-point> store.64 %arg1 -> 0[x] - load.64 %r29 <- 0[x] - load.32 %r30 <- 0[%r29] - trunc.3 %r31 <- (32) %r30 - add.3 %r32 <- %r31, $1 - load.32 %r33 <- 0[%r29] - zext.32 %r34 <- (3) %r32 - and.32 %r35 <- %r33, $-8 - or.32 %r36 <- %r35, %r34 - store.32 %r36 -> 0[%r29] - zext.32 %r37 <- (3) %r31 - phisrc.32 %phi3(return) <- %r37 + load.64 %r33 <- 0[x] + load.32 %r34 <- 0[%r33] + trunc.3 %r35 <- (32) %r34 + zext.32 %r36 <- (3) %r35 + add.32 %r37 <- %r36, $1 + trunc.3 %r38 <- (32) %r37 + load.32 %r39 <- 0[%r33] + zext.32 %r40 <- (3) %r38 + and.32 %r41 <- %r39, $0xfffffff8 + or.32 %r42 <- %r41, %r40 + store.32 %r42 -> 0[%r33] + zext.32 %r43 <- (3) %r36 + phisrc.32 %phi3(return) <- %r43 br .L7 .L7: - phi.32 %r38 <- %phi3(return) - ret.32 %r38 + phi.32 %r44 <- %phi3(return) + ret.32 %r44 spreinc: .L8: <entry-point> store.64 %arg1 -> 0[x] - load.64 %r39 <- 0[x] - load.32 %r40 <- 0[%r39] - trunc.3 %r41 <- (32) %r40 - add.3 %r42 <- %r41, $1 - load.32 %r43 <- 0[%r39] - zext.32 %r44 <- (3) %r42 - and.32 %r45 <- %r43, $-8 - or.32 %r46 <- %r45, %r44 - store.32 %r46 -> 0[%r39] - zext.32 %r47 <- (3) %r42 - phisrc.32 %phi4(return) <- %r47 + load.64 %r45 <- 0[x] + load.32 %r46 <- 0[%r45] + trunc.3 %r47 <- (32) %r46 + zext.32 %r48 <- (3) %r47 + add.32 %r49 <- %r48, $1 + trunc.3 %r50 <- (32) %r49 + load.32 %r51 <- 0[%r45] + zext.32 %r52 <- (3) %r50 + and.32 %r53 <- %r51, $0xfffffff8 + or.32 %r54 <- %r53, %r52 + store.32 %r54 -> 0[%r45] + zext.32 %r55 <- (3) %r50 + phisrc.32 %phi4(return) <- %r55 br .L9 .L9: - phi.32 %r48 <- %phi4(return) - ret.32 %r48 + phi.32 %r56 <- %phi4(return) + ret.32 %r56 scpy: @@ -155,15 +163,15 @@ scpy: <entry-point> store.64 %arg1 -> 0[d] store.64 %arg2 -> 0[s] - load.64 %r49 <- 0[s] - load.32 %r50 <- 0[%r49] - trunc.3 %r51 <- (32) %r50 - load.64 %r52 <- 0[d] - load.32 %r53 <- 0[%r52] - zext.32 %r54 <- (3) %r51 - and.32 %r55 <- %r53, $-8 - or.32 %r56 <- %r55, %r54 - store.32 %r56 -> 0[%r52] + load.64 %r57 <- 0[s] + load.32 %r58 <- 0[%r57] + trunc.3 %r59 <- (32) %r58 + load.64 %r60 <- 0[d] + load.32 %r61 <- 0[%r60] + zext.32 %r62 <- (3) %r59 + and.32 %r63 <- %r61, $0xfffffff8 + or.32 %r64 <- %r63, %r62 + store.32 %r64 -> 0[%r60] br .L11 .L11: diff --git a/validation/linear/bitfield-store.c b/validation/linear/bitfield-store.c new file mode 100644 index 00000000..3d952c8d --- /dev/null +++ b/validation/linear/bitfield-store.c @@ -0,0 +1,22 @@ +int foo(void) +{ + struct { + int a:8; + int b:16; + int c:8; + } s = { 0xff, 0x0000, 0xff }; + + return s.b = 0x56781234; +} + +/* + * check-name: bitfield-store + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: ret\\..*\\$0x1234 + * + * check-error-start +linear/bitfield-store.c:9:22: warning: cast truncates bits from constant value (56781234 becomes 1234) + * check-error-end + */ diff --git a/validation/linear/call-complex-pointer.c b/validation/linear/call-complex-pointer.c index ea8232f1..dc0ab07b 100644 --- a/validation/linear/call-complex-pointer.c +++ b/validation/linear/call-complex-pointer.c @@ -18,14 +18,14 @@ foo: br .L4 .L3: - ptrcast.64 %r5 <- (64) %arg3 - phisrc.64 %phi2 <- %r5 + ptrcast.64 %r6 <- (64) %arg3 + phisrc.64 %phi2 <- %r6 br .L4 .L4: - phi.64 %r6 <- %phi1, %phi2 - call.32 %r7 <- %r6, %arg4 - ret.32 %r7 + phi.64 %r7 <- %phi1, %phi2 + call.32 %r8 <- %r7, %arg4 + ret.32 %r8 * check-output-end diff --git a/validation/linear/cast-constant-to-float.c b/validation/linear/cast-constant-to-float.c index ef7892f1..ac4eff0f 100644 --- a/validation/linear/cast-constant-to-float.c +++ b/validation/linear/cast-constant-to-float.c @@ -13,21 +13,21 @@ double f3(void) { return -1.0; } f1: .L0: <entry-point> - setfval.64 %r1 <- -1.000000 + setfval.64 %r1 <- -1.000000e+00 ret.64 %r1 f2: .L2: <entry-point> - setfval.64 %r3 <- -1.000000 + setfval.64 %r3 <- -1.000000e+00 ret.64 %r3 f3: .L4: <entry-point> - setfval.64 %r5 <- -1.000000 + setfval.64 %r5 <- -1.000000e+00 ret.64 %r5 diff --git a/validation/linear/cast-constants.c b/validation/linear/cast-constants.c index 9e200672..c1fdab41 100644 --- a/validation/linear/cast-constants.c +++ b/validation/linear/cast-constants.c @@ -286,70 +286,70 @@ vptr_2_iptr: int_2_float: .L76: <entry-point> - setfval.32 %r39 <- 123.000000 + setfval.32 %r39 <- 1.230000e+02 ret.32 %r39 uint_2_float: .L78: <entry-point> - setfval.32 %r41 <- 123.000000 + setfval.32 %r41 <- 1.230000e+02 ret.32 %r41 long_2_float: .L80: <entry-point> - setfval.32 %r43 <- 123.000000 + setfval.32 %r43 <- 1.230000e+02 ret.32 %r43 ulong_2_float: .L82: <entry-point> - setfval.32 %r45 <- 123.000000 + setfval.32 %r45 <- 1.230000e+02 ret.32 %r45 double_2_float: .L84: <entry-point> - setfval.32 %r47 <- 1.123000 + setfval.32 %r47 <- 1.123000e+00 ret.32 %r47 int_2_double: .L86: <entry-point> - setfval.64 %r49 <- 123.000000 + setfval.64 %r49 <- 1.230000e+02 ret.64 %r49 uint_2_double: .L88: <entry-point> - setfval.64 %r51 <- 123.000000 + setfval.64 %r51 <- 1.230000e+02 ret.64 %r51 long_2_double: .L90: <entry-point> - setfval.64 %r53 <- 123.000000 + setfval.64 %r53 <- 1.230000e+02 ret.64 %r53 ulong_2_double: .L92: <entry-point> - setfval.64 %r55 <- 123.000000 + setfval.64 %r55 <- 1.230000e+02 ret.64 %r55 float_2_double: .L94: <entry-point> - setfval.64 %r57 <- 1.123000 + setfval.64 %r57 <- 1.123000e+00 ret.64 %r57 diff --git a/validation/linear/logical.c b/validation/linear/logical.c new file mode 100644 index 00000000..148ad427 --- /dev/null +++ b/validation/linear/logical.c @@ -0,0 +1,259 @@ +struct S { + int :1; + signed int s:2; + unsigned int u:3; + long l; + double d; +}; + +int os(int i, struct S *b) { return i || b->s; } +int ou(int i, struct S *b) { return i || b->u; } +int ol(int i, struct S *b) { return i || b->l; } +int od(int i, struct S *b) { return i || b->d; } + +int as(int i, struct S *b) { return i && b->s; } +int au(int i, struct S *b) { return i && b->u; } +int al(int i, struct S *b) { return i && b->l; } +int ad(int i, struct S *b) { return i && b->d; } + +/* + * check-name: logical + * check-command: test-linearize -m64 -fdump-ir -Wno-decl $file + * + * check-output-start +os: +.L0: + <entry-point> + store.32 %arg1 -> 0[i] + store.64 %arg2 -> 0[b] + phisrc.32 %phi1 <- $1 + load.32 %r1 <- 0[i] + setne.1 %r2 <- %r1, $0 + cbr %r2, .L3, .L2 + +.L2: + load.64 %r3 <- 0[b] + load.32 %r4 <- 0[%r3] + lsr.32 %r5 <- %r4, $1 + trunc.2 %r6 <- (32) %r5 + setne.1 %r7 <- %r6, $0 + zext.32 %r8 <- (1) %r7 + phisrc.32 %phi2 <- %r8 + br .L3 + +.L3: + phi.32 %r9 <- %phi1, %phi2 + phisrc.32 %phi3(return) <- %r9 + br .L1 + +.L1: + phi.32 %r10 <- %phi3(return) + ret.32 %r10 + + +ou: +.L4: + <entry-point> + store.32 %arg1 -> 0[i] + store.64 %arg2 -> 0[b] + phisrc.32 %phi5 <- $1 + load.32 %r11 <- 0[i] + setne.1 %r12 <- %r11, $0 + cbr %r12, .L7, .L6 + +.L6: + load.64 %r13 <- 0[b] + load.32 %r14 <- 0[%r13] + lsr.32 %r15 <- %r14, $3 + trunc.3 %r16 <- (32) %r15 + setne.1 %r17 <- %r16, $0 + zext.32 %r18 <- (1) %r17 + phisrc.32 %phi6 <- %r18 + br .L7 + +.L7: + phi.32 %r19 <- %phi5, %phi6 + phisrc.32 %phi7(return) <- %r19 + br .L5 + +.L5: + phi.32 %r20 <- %phi7(return) + ret.32 %r20 + + +ol: +.L8: + <entry-point> + store.32 %arg1 -> 0[i] + store.64 %arg2 -> 0[b] + phisrc.32 %phi9 <- $1 + load.32 %r21 <- 0[i] + setne.1 %r22 <- %r21, $0 + cbr %r22, .L11, .L10 + +.L10: + load.64 %r23 <- 0[b] + load.64 %r24 <- 8[%r23] + setne.1 %r25 <- %r24, $0 + zext.32 %r26 <- (1) %r25 + phisrc.32 %phi10 <- %r26 + br .L11 + +.L11: + phi.32 %r27 <- %phi9, %phi10 + phisrc.32 %phi11(return) <- %r27 + br .L9 + +.L9: + phi.32 %r28 <- %phi11(return) + ret.32 %r28 + + +od: +.L12: + <entry-point> + store.32 %arg1 -> 0[i] + store.64 %arg2 -> 0[b] + phisrc.32 %phi13 <- $1 + load.32 %r29 <- 0[i] + setne.1 %r30 <- %r29, $0 + cbr %r30, .L15, .L14 + +.L14: + load.64 %r31 <- 0[b] + load.64 %r32 <- 16[%r31] + setfval.64 %r33 <- 0.000000e+00 + fcmpune.1 %r34 <- %r32, %r33 + zext.32 %r35 <- (1) %r34 + phisrc.32 %phi14 <- %r35 + br .L15 + +.L15: + phi.32 %r36 <- %phi13, %phi14 + phisrc.32 %phi15(return) <- %r36 + br .L13 + +.L13: + phi.32 %r37 <- %phi15(return) + ret.32 %r37 + + +as: +.L16: + <entry-point> + store.32 %arg1 -> 0[i] + store.64 %arg2 -> 0[b] + phisrc.32 %phi17 <- $0 + load.32 %r38 <- 0[i] + setne.1 %r39 <- %r38, $0 + cbr %r39, .L18, .L19 + +.L18: + load.64 %r40 <- 0[b] + load.32 %r41 <- 0[%r40] + lsr.32 %r42 <- %r41, $1 + trunc.2 %r43 <- (32) %r42 + setne.1 %r44 <- %r43, $0 + zext.32 %r45 <- (1) %r44 + phisrc.32 %phi18 <- %r45 + br .L19 + +.L19: + phi.32 %r46 <- %phi18, %phi17 + phisrc.32 %phi19(return) <- %r46 + br .L17 + +.L17: + phi.32 %r47 <- %phi19(return) + ret.32 %r47 + + +au: +.L20: + <entry-point> + store.32 %arg1 -> 0[i] + store.64 %arg2 -> 0[b] + phisrc.32 %phi21 <- $0 + load.32 %r48 <- 0[i] + setne.1 %r49 <- %r48, $0 + cbr %r49, .L22, .L23 + +.L22: + load.64 %r50 <- 0[b] + load.32 %r51 <- 0[%r50] + lsr.32 %r52 <- %r51, $3 + trunc.3 %r53 <- (32) %r52 + setne.1 %r54 <- %r53, $0 + zext.32 %r55 <- (1) %r54 + phisrc.32 %phi22 <- %r55 + br .L23 + +.L23: + phi.32 %r56 <- %phi22, %phi21 + phisrc.32 %phi23(return) <- %r56 + br .L21 + +.L21: + phi.32 %r57 <- %phi23(return) + ret.32 %r57 + + +al: +.L24: + <entry-point> + store.32 %arg1 -> 0[i] + store.64 %arg2 -> 0[b] + phisrc.32 %phi25 <- $0 + load.32 %r58 <- 0[i] + setne.1 %r59 <- %r58, $0 + cbr %r59, .L26, .L27 + +.L26: + load.64 %r60 <- 0[b] + load.64 %r61 <- 8[%r60] + setne.1 %r62 <- %r61, $0 + zext.32 %r63 <- (1) %r62 + phisrc.32 %phi26 <- %r63 + br .L27 + +.L27: + phi.32 %r64 <- %phi26, %phi25 + phisrc.32 %phi27(return) <- %r64 + br .L25 + +.L25: + phi.32 %r65 <- %phi27(return) + ret.32 %r65 + + +ad: +.L28: + <entry-point> + store.32 %arg1 -> 0[i] + store.64 %arg2 -> 0[b] + phisrc.32 %phi29 <- $0 + load.32 %r66 <- 0[i] + setne.1 %r67 <- %r66, $0 + cbr %r67, .L30, .L31 + +.L30: + load.64 %r68 <- 0[b] + load.64 %r69 <- 16[%r68] + setfval.64 %r70 <- 0.000000e+00 + fcmpune.1 %r71 <- %r69, %r70 + zext.32 %r72 <- (1) %r71 + phisrc.32 %phi30 <- %r72 + br .L31 + +.L31: + phi.32 %r73 <- %phi30, %phi29 + phisrc.32 %phi31(return) <- %r73 + br .L29 + +.L29: + phi.32 %r74 <- %phi31(return) + ret.32 %r74 + + + * check-output-end + */ diff --git a/validation/loop-linearization.c b/validation/loop-linearization.c index 25c6dfb8..051e0453 100644 --- a/validation/loop-linearization.c +++ b/validation/loop-linearization.c @@ -56,8 +56,8 @@ ffor: br .L7 .L2: - add.32 %r7 <- %r1(i), $1 - phisrc.32 %phi6(i) <- %r7 + add.32 %r8 <- %r1(i), $1 + phisrc.32 %phi6(i) <- %r8 br .L4 .L3: @@ -65,8 +65,8 @@ ffor: br .L7 .L7: - phi.32 %r5 <- %phi1(return), %phi2(return) - ret.32 %r5 + phi.32 %r6 <- %phi1(return), %phi2(return) + ret.32 %r6 fwhile: @@ -76,21 +76,21 @@ fwhile: br .L12 .L12: - phi.32 %r8(i) <- %phi11(i), %phi12(i) - setlt.32 %r9 <- %r8(i), $10 - cbr %r9, .L9, .L11 + phi.32 %r9(i) <- %phi11(i), %phi12(i) + setlt.32 %r10 <- %r9(i), $10 + cbr %r10, .L9, .L11 .L9: - call.32 %r11 <- p, %r8(i) - cbr %r11, .L14, .L13 + call.32 %r12 <- p, %r9(i) + cbr %r12, .L14, .L13 .L13: phisrc.32 %phi7(return) <- $0 br .L15 .L14: - add.32 %r14 <- %r8(i), $1 - phisrc.32 %phi12(i) <- %r14 + add.32 %r16 <- %r9(i), $1 + phisrc.32 %phi12(i) <- %r16 br .L12 .L11: @@ -98,8 +98,8 @@ fwhile: br .L15 .L15: - phi.32 %r12 <- %phi7(return), %phi8(return) - ret.32 %r12 + phi.32 %r14 <- %phi7(return), %phi8(return) + ret.32 %r14 fdo: @@ -109,27 +109,27 @@ fdo: br .L17 .L17: - phi.32 %r15(i) <- %phi16(i), %phi17(i) - call.32 %r16 <- p, %r15(i) - cbr %r16, .L18, .L20 + phi.32 %r17(i) <- %phi16(i), %phi17(i) + call.32 %r18 <- p, %r17(i) + cbr %r18, .L18, .L20 .L20: phisrc.32 %phi13(return) <- $0 br .L22 .L18: - add.32 %r19 <- %r15(i), $1 - setlt.32 %r20 <- %r15(i), $10 - phisrc.32 %phi17(i) <- %r19 - cbr %r20, .L17, .L19 + add.32 %r22 <- %r17(i), $1 + setlt.32 %r23 <- %r17(i), $10 + phisrc.32 %phi17(i) <- %r22 + cbr %r23, .L17, .L19 .L19: phisrc.32 %phi14(return) <- $1 br .L22 .L22: - phi.32 %r17 <- %phi13(return), %phi14(return) - ret.32 %r17 + phi.32 %r20 <- %phi13(return), %phi14(return) + ret.32 %r20 * check-output-end diff --git a/validation/optim/and-extend.c b/validation/optim/and-extend.c new file mode 100644 index 00000000..eb589236 --- /dev/null +++ b/validation/optim/and-extend.c @@ -0,0 +1,27 @@ +typedef unsigned short u16; +typedef short s16; +typedef unsigned int u32; +typedef int s32; + +u32 ufoo(u32 x) +{ + u16 i = ((u16)x) & 0x7fffU; + return i; +} + +u32 sfoo(u32 x) +{ + s16 i = ((s16)x) & 0x7fff; + return i; +} + +/* + * check-name: and-extend + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: trunc\\. + * check-output-excludes: zext\\. + * check-output-excludes: sext\\. + * check-output-contains: and\\.32.*0x7fff + */ diff --git a/validation/optim/and-extendx.c b/validation/optim/and-extendx.c new file mode 100644 index 00000000..5c181c93 --- /dev/null +++ b/validation/optim/and-extendx.c @@ -0,0 +1,24 @@ +typedef unsigned short u16; +typedef short s16; +typedef unsigned int u32; +typedef int s32; +typedef unsigned long long u64; +typedef long long s64; + +u64 ufoo(int x) +{ + return x & 0x7fff; +} + +u64 sfoo(int x) +{ + return x & 0x7fff; +} + +/* + * check-name: and-extend + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: and\\.64.*0x7fff + */ diff --git a/validation/optim/and-lsr.c b/validation/optim/and-lsr.c new file mode 100644 index 00000000..439eb822 --- /dev/null +++ b/validation/optim/and-lsr.c @@ -0,0 +1,15 @@ +// (x & M) >> S to (x >> S) & (M >> S) + +unsigned int foo(unsigned int x) +{ + return (x & 0xffff) >> 12; +} + +/* + * check-name: and-lsr + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: and\\..*\\$15 + * check-output-excludes: and\\..*\\$0xffff + */ diff --git a/validation/optim/and-or-bf0.c b/validation/optim/and-or-bf0.c new file mode 100644 index 00000000..cfaff4f2 --- /dev/null +++ b/validation/optim/and-or-bf0.c @@ -0,0 +1,24 @@ +struct s { + int f:3; +}; + +void foo(struct s *p, int a) +{ + p->f = 1; + p->f = a; +} + +void bar(struct s *p, int a) +{ + p->f = a; + p->f = 1; +} + +/* + * check-name: and-or-bf0 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(3): and\\. + * check-output-pattern(2): or\\. + */ diff --git a/validation/optim/and-or-bf1.c b/validation/optim/and-or-bf1.c new file mode 100644 index 00000000..23477ff3 --- /dev/null +++ b/validation/optim/and-or-bf1.c @@ -0,0 +1,18 @@ +struct s { + int :2; + int f:3; +}; + +void foo(struct s *d, const struct s *s, int a) +{ + d->f = s->f | a; +} + +/* + * check-name: and-or-bf1 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(2): and\\. + * check-output-pattern(2): or\\. + */ diff --git a/validation/optim/and-or-bf2.c b/validation/optim/and-or-bf2.c new file mode 100644 index 00000000..2296da12 --- /dev/null +++ b/validation/optim/and-or-bf2.c @@ -0,0 +1,27 @@ +struct s { + char a:3; + char b:3; + char c:2; +}; + +void foo(struct s *p) +{ + p->a = 1; + p->b = 2; + p->c = 3; +} + +/* + * check-name: and-or-bf2 + * check-command: test-linearize -Wno-decl $file + * + * check-output-start +foo: +.L0: + <entry-point> + store.8 $209 -> 0[%arg1] + ret + + + * check-output-end + */ diff --git a/validation/optim/and-or-bfs.c b/validation/optim/and-or-bfs.c new file mode 100644 index 00000000..f3f33204 --- /dev/null +++ b/validation/optim/and-or-bfs.c @@ -0,0 +1,23 @@ +struct s { + signed int :2; + signed int f:3; +}; + +int bfs(struct s s, int a) +{ + s.f = a; + return s.f; +} + +/* + * check-name: and-or-bfs + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(1): trunc\\. + * check-output-pattern(1): sext\\. + * check-output-excludes: and\\. + * check-output-excludes: or\\. + * check-output-excludes: shl\\. + * check-output-excludes: lsr\\. + */ diff --git a/validation/optim/and-or-bfu.c b/validation/optim/and-or-bfu.c new file mode 100644 index 00000000..b6a080bd --- /dev/null +++ b/validation/optim/and-or-bfu.c @@ -0,0 +1,21 @@ +struct u { + unsigned int :2; + unsigned int f:3; +}; + +int bfu(struct u s, int a) +{ + s.f = a; + return s.f; +} + +/* + * check-name: and-or-bfu + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(1): and\\. + * check-output-excludes: or\\. + * check-output-excludes: shl\\. + * check-output-excludes: lsr\\. + */ diff --git a/validation/optim/and-or-bfx.c b/validation/optim/and-or-bfx.c new file mode 100644 index 00000000..57a54cf5 --- /dev/null +++ b/validation/optim/and-or-bfx.c @@ -0,0 +1,18 @@ +struct s { + int f:3; +}; + +void foo(struct s *p, int a, int b) +{ + p->f = a; + p->f = b; +} + +/* + * check-name: and-or-bfx + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(2): and\\. + * check-output-pattern(1): or\\. + */ diff --git a/validation/optim/and-or-constant0.c b/validation/optim/and-or-constant0.c new file mode 100644 index 00000000..dcf440f3 --- /dev/null +++ b/validation/optim/and-or-constant0.c @@ -0,0 +1,12 @@ +int foo(int x) +{ + return (x | 0xfffff000) & 0xfff; +} + +/* + * check-name: and-or-constant0 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: or\\. + */ diff --git a/validation/optim/and-or-constant1.c b/validation/optim/and-or-constant1.c new file mode 100644 index 00000000..49823d5c --- /dev/null +++ b/validation/optim/and-or-constant1.c @@ -0,0 +1,14 @@ +int foo(int x) +{ + return (x | 0x000fffff) & 0xfff; +} + +/* + * check-name: or-and-constant1 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: ret\\..*\\$0xfff + * check-output-excludes: and\\. + * check-output-excludes: or\\. + */ diff --git a/validation/optim/and-or-constant2.c b/validation/optim/and-or-constant2.c new file mode 100644 index 00000000..d7e66f9c --- /dev/null +++ b/validation/optim/and-or-constant2.c @@ -0,0 +1,13 @@ +int foo(int x) +{ + return (x | 0xfffffff0) & 0xfff; +} + +/* + * check-name: and-or-constant2 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: or\\..*\\$0xff0 + * check-output-excludes: or\\..*\\$0xfffffff0 + */ diff --git a/validation/optim/and-or-crash.c b/validation/optim/and-or-crash.c new file mode 100644 index 00000000..98a8a9b8 --- /dev/null +++ b/validation/optim/and-or-crash.c @@ -0,0 +1,5 @@ +static unsigned a(unsigned b, unsigned c) { (c << 1 | b & 1 << 1) >> 1; } + +/* + * check-name: catch crashes during AND-OR simplifications + */ diff --git a/validation/optim/and-or-lsr0.c b/validation/optim/and-or-lsr0.c new file mode 100644 index 00000000..227c5aed --- /dev/null +++ b/validation/optim/and-or-lsr0.c @@ -0,0 +1,13 @@ +int foo(int a, int b) +{ + return ((a & 0x00000fff) | b) >> 12; +} + +/* + * check-name: and-or-lsr0 + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-excludes: or\\. + */ diff --git a/validation/optim/and-or-lsr1.c b/validation/optim/and-or-lsr1.c new file mode 100644 index 00000000..bd1dbc8a --- /dev/null +++ b/validation/optim/and-or-lsr1.c @@ -0,0 +1,13 @@ +int foo(int a, int b) +{ + return ((a & 0xfffff000) | b) >> 12; +} + +/* + * check-name: and-or-lsr1 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(0): and\\. + * check-output-pattern(1): or\\. + */ diff --git a/validation/optim/and-or-lsr2.c b/validation/optim/and-or-lsr2.c new file mode 100644 index 00000000..d1af0135 --- /dev/null +++ b/validation/optim/and-or-lsr2.c @@ -0,0 +1,13 @@ +int foo(int x, int y) +{ + return ((x & 0xf0ffffff) | y) >> 12; +} + +/* + * check-name: and-or-lsr2 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: and\\..*\\$0xf0fff + * check-output-excludes: and\\..*\\$0xf0ffffff + */ diff --git a/validation/optim/and-or-lsrx.c b/validation/optim/and-or-lsrx.c new file mode 100644 index 00000000..31adca92 --- /dev/null +++ b/validation/optim/and-or-lsrx.c @@ -0,0 +1,13 @@ +unsigned int foo(unsigned int x, unsigned int y, unsigned int a) +{ + return ((x & y) | (a & 0x0fff)) >> 12; +} + +/* + * check-name: and-or-lsrx + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(1): and\\. + * check-output-excludes: or\\. + */ diff --git a/validation/optim/and-or-mask.c b/validation/optim/and-or-mask.c new file mode 100644 index 00000000..46803789 --- /dev/null +++ b/validation/optim/and-or-mask.c @@ -0,0 +1,18 @@ +int foo(int a, int b) +{ + return ((a & 7) | (b & 3)) & 8; +} + +/* + * check-name: and-or-mask + * check-command: test-linearize -Wno-decl $file + * + * check-output-start +foo: +.L0: + <entry-point> + ret.32 $0 + + + * check-output-end + */ diff --git a/validation/optim/and-or-mask0.c b/validation/optim/and-or-mask0.c new file mode 100644 index 00000000..2d2245ea --- /dev/null +++ b/validation/optim/and-or-mask0.c @@ -0,0 +1,12 @@ +int foo(int a, int b) +{ + return ((a & 0xfffff000) | b) & 0xfff; +} + +/* + * check-name: and-or-mask0 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: or\\. + */ diff --git a/validation/optim/and-or-mask1.c b/validation/optim/and-or-mask1.c new file mode 100644 index 00000000..bff3a89f --- /dev/null +++ b/validation/optim/and-or-mask1.c @@ -0,0 +1,13 @@ +int foo(int a, int b) +{ + return ((a & 0x0fffffff) | b) & 0xfff; +} + +/* + * check-name: and-or-mask1 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(1): and\\. + * check-output-pattern(1): or\\. + */ diff --git a/validation/optim/and-or-mask2.c b/validation/optim/and-or-mask2.c new file mode 100644 index 00000000..cab802a6 --- /dev/null +++ b/validation/optim/and-or-mask2.c @@ -0,0 +1,13 @@ +int foo(int x, int y) +{ + return ((x & 0xffffff0f) | y) & 0xfff; +} + +/* + * check-name: and-or-mask2 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: and\\..*\\$0xf0f + * check-output-excludes: and\\..*\\$0xffffff0f + */ diff --git a/validation/optim/and-or-mask3s.c b/validation/optim/and-or-mask3s.c new file mode 100644 index 00000000..cf264723 --- /dev/null +++ b/validation/optim/and-or-mask3s.c @@ -0,0 +1,25 @@ +#define W 3 +#define S 8 +#define M (W << S) + +static inline int fun(unsigned int x, unsigned int y) +{ + return ((x & M) | (y << S)) >> S; +} + +short foo(unsigned int x, unsigned int y) +{ + return fun(x, y) & W; +} + +/* + * check-name: and-or-mask3s + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-pattern(1): lsr\\. + * check-output-pattern(1): or\\. + * check-output-pattern(1): and\\. + * check-output-excludes: shl\\. + */ diff --git a/validation/optim/and-or-mask3u.c b/validation/optim/and-or-mask3u.c new file mode 100644 index 00000000..c5b6c5fa --- /dev/null +++ b/validation/optim/and-or-mask3u.c @@ -0,0 +1,25 @@ +#define W 3 +#define S 8 +#define M (W << S) + +static inline int fun(unsigned int x, unsigned int y) +{ + return ((x & M) | (y << S)) >> S; +} + +int foo(unsigned int x, unsigned int y) +{ + return fun(x, y) & W; +} + +/* + * check-name: and-or-mask3u + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-pattern(1): lsr\\. + * check-output-pattern(1): or\\. + * check-output-pattern(1): and\\. + * check-output-excludes: shl\\. + */ diff --git a/validation/optim/and-or-mask4.c b/validation/optim/and-or-mask4.c new file mode 100644 index 00000000..1c4bc01a --- /dev/null +++ b/validation/optim/and-or-mask4.c @@ -0,0 +1,25 @@ +#define W 3 +#define S 8 +#define M (W << S) + +static inline int fun(unsigned int x, unsigned int y) +{ + return ((x & W) | (y >> S)) << S; +} + +int foo(unsigned int x, unsigned int y) +{ + return fun(x, y) & M; +} + +/* + * check-name: and-or-mask4 + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-pattern(1): shl\\. + * check-output-pattern(1): or\\. + * check-output-pattern(1): and\\. + * check-output-excludes: lsr\\. + */ diff --git a/validation/optim/and-or-maskx.c b/validation/optim/and-or-maskx.c new file mode 100644 index 00000000..21d44e8d --- /dev/null +++ b/validation/optim/and-or-maskx.c @@ -0,0 +1,13 @@ +int foo(int x, int y, int a) +{ + return ((x & y) | (a & 0xf000)) & 0x0fff; +} + +/* + * check-name: and-or-maskx + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(2): and\\. + * check-output-excludes: or\\. + */ diff --git a/validation/optim/and-or-shl0.c b/validation/optim/and-or-shl0.c new file mode 100644 index 00000000..4850b326 --- /dev/null +++ b/validation/optim/and-or-shl0.c @@ -0,0 +1,12 @@ +int foo(int a, int b) +{ + return ((a & 0xfff00000) | b) << 12; +} + +/* + * check-name: and-or-shl0 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: or\\. + */ diff --git a/validation/optim/and-or-shl1.c b/validation/optim/and-or-shl1.c new file mode 100644 index 00000000..bea22245 --- /dev/null +++ b/validation/optim/and-or-shl1.c @@ -0,0 +1,13 @@ +int foo(int a, int b) +{ + return ((a & 0x000fffff) | b) << 12; +} + +/* + * check-name: and-or-shl1 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(0): and\\. + * check-output-pattern(1): or\\. + */ diff --git a/validation/optim/and-or-shl2.c b/validation/optim/and-or-shl2.c new file mode 100644 index 00000000..f5f62758 --- /dev/null +++ b/validation/optim/and-or-shl2.c @@ -0,0 +1,13 @@ +int foo(int x, int y) +{ + return ((x & 0xffffff0f) | y) << 12; +} + +/* + * check-name: and-or-shl2 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: and\\..*\\$0xfff0f + * check-output-excludes: and\\..*\\$0xffffff0f + */ diff --git a/validation/optim/and-or-shlx.c b/validation/optim/and-or-shlx.c new file mode 100644 index 00000000..ec2a2ced --- /dev/null +++ b/validation/optim/and-or-shlx.c @@ -0,0 +1,13 @@ +unsigned int foo(unsigned int x, unsigned int y, unsigned int a) +{ + return ((x & y) | (a & 0xfff00000)) << 12; +} + +/* + * check-name: and-or-shlx + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(1): and\\. + * check-output-excludes: or\\. + */ diff --git a/validation/optim/and-or-trunc0.c b/validation/optim/and-or-trunc0.c new file mode 100644 index 00000000..3d326b6a --- /dev/null +++ b/validation/optim/and-or-trunc0.c @@ -0,0 +1,13 @@ +char foo(int x, int y) +{ + return (x & 0xff00) | y; +} + +/* + * check-name: and-or-trunc0 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: and\\. + * check-output-excludes: or\\. + */ diff --git a/validation/optim/and-or-trunc1.c b/validation/optim/and-or-trunc1.c new file mode 100644 index 00000000..6bbe8a8c --- /dev/null +++ b/validation/optim/and-or-trunc1.c @@ -0,0 +1,12 @@ +char foo(int x, int y) +{ + return (x & 0xffff) | y; +} + +/* + * check-name: and-or-trunc1 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: and\\. + */ diff --git a/validation/optim/and-or-trunc2.c b/validation/optim/and-or-trunc2.c new file mode 100644 index 00000000..e66c1f14 --- /dev/null +++ b/validation/optim/and-or-trunc2.c @@ -0,0 +1,13 @@ +char foo(int x, int y) +{ + return (x & 0xff07) | y; +} + +/* + * check-name: and-or-trunc2 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(1): and\\. + * check-output-pattern(1): and\\..*\\$7 + */ diff --git a/validation/optim/and-or-truncx.c b/validation/optim/and-or-truncx.c new file mode 100644 index 00000000..ef8249a1 --- /dev/null +++ b/validation/optim/and-or-truncx.c @@ -0,0 +1,13 @@ +char foo(int x, int y, int b) +{ + return (x & y) | (b & 0xff00); +} + +/* + * check-name: and-or-truncx + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(1): and\\. + * check-output-excludes: or\\. + */ diff --git a/validation/optim/and-trunc.c b/validation/optim/and-trunc.c new file mode 100644 index 00000000..df1e4d03 --- /dev/null +++ b/validation/optim/and-trunc.c @@ -0,0 +1,20 @@ +short smask(short x) +{ + return x & (short) 0x7fff; +} + +short umask(unsigned short x) +{ + return x & (unsigned short) 0x7fff; +} + +/* + * check-name: and-trunc + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: sext\\. + * check-output-excludes: zext\\. + * check-output-excludes: trunc\\. + * check-output-contains: and\\.16 + */ diff --git a/validation/optim/bitfield-store-load0.c b/validation/optim/bitfield-store-load0.c new file mode 100644 index 00000000..f68cb600 --- /dev/null +++ b/validation/optim/bitfield-store-load0.c @@ -0,0 +1,44 @@ +int ufoo(unsigned int a) +{ + struct u { + unsigned int :2; + unsigned int a:3; + } bf; + + bf.a = a; + return bf.a; +} + +int sfoo(int a) +{ + struct s { + signed int :2; + signed int a:3; + } bf; + + bf.a = a; + return bf.a; +} + +/* + * check-name: optim store/load bitfields + * check-command: test-linearize -Wno-decl $file + * + * check-output-start +ufoo: +.L0: + <entry-point> + and.32 %r11 <- %arg1, $7 + ret.32 %r11 + + +sfoo: +.L2: + <entry-point> + trunc.3 %r16 <- (32) %arg1 + sext.32 %r23 <- (3) %r16 + ret.32 %r23 + + + * check-output-end + */ diff --git a/validation/optim/bitfield-store-loads.c b/validation/optim/bitfield-store-loads.c new file mode 100644 index 00000000..dc625131 --- /dev/null +++ b/validation/optim/bitfield-store-loads.c @@ -0,0 +1,23 @@ +struct s { + char :2; + char f:3; +}; + +int foo(struct s s, int a) +{ + s.f = a; + return s.f; +} + +/* + * check-name: bitfield-store-load signed + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: shl\\. + * check-output-excludes: lsr\\. + * check-output-excludes: or\\. + * check-output-excludes: [sz]ext\\. + * check-output-excludes: trunc\\. + * check-output-pattern(1): and\\. + */ diff --git a/validation/optim/bitfield-store-loadu.c b/validation/optim/bitfield-store-loadu.c new file mode 100644 index 00000000..7fa1593d --- /dev/null +++ b/validation/optim/bitfield-store-loadu.c @@ -0,0 +1,21 @@ +struct s { + unsigned int :2; + unsigned int f:3; +}; + +int foo(struct s s, int a) +{ + s.f = a; + return s.f; +} + +/* + * check-name: bitfield-store-load unsigned + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: shl\\. + * check-output-excludes: lsr\\. + * check-output-excludes: or\\. + * check-output-pattern(1): and\\. + */ diff --git a/validation/optim/bool-context-fp.c b/validation/optim/bool-context-fp.c index 50e96825..c41370ba 100644 --- a/validation/optim/bool-context-fp.c +++ b/validation/optim/bool-context-fp.c @@ -18,7 +18,7 @@ int ifand(float a, float b) { return a && b; } bfimp: .L0: <entry-point> - setfval.32 %r2 <- 0.000000 + setfval.32 %r2 <- 0.000000e+00 fcmpune.1 %r3 <- %arg1, %r2 ret.1 %r3 @@ -26,7 +26,7 @@ bfimp: bfexp: .L2: <entry-point> - setfval.32 %r6 <- 0.000000 + setfval.32 %r6 <- 0.000000e+00 fcmpune.1 %r7 <- %arg1, %r6 ret.1 %r7 @@ -34,7 +34,7 @@ bfexp: bfnot: .L4: <entry-point> - setfval.32 %r10 <- 0.000000 + setfval.32 %r10 <- 0.000000e+00 fcmpoeq.1 %r12 <- %arg1, %r10 ret.1 %r12 @@ -42,7 +42,7 @@ bfnot: ifnot: .L6: <entry-point> - setfval.32 %r15 <- 0.000000 + setfval.32 %r15 <- 0.000000e+00 fcmpoeq.32 %r16 <- %arg1, %r15 ret.32 %r16 @@ -50,18 +50,17 @@ ifnot: bfior: .L8: <entry-point> - setfval.32 %r19 <- 0.000000 + setfval.32 %r19 <- 0.000000e+00 fcmpune.1 %r20 <- %arg1, %r19 fcmpune.1 %r23 <- %arg2, %r19 or.1 %r24 <- %r20, %r23 - setne.1 %r26 <- %r24, $0 - ret.1 %r26 + ret.1 %r24 ifior: .L10: <entry-point> - setfval.32 %r29 <- 0.000000 + setfval.32 %r29 <- 0.000000e+00 fcmpune.1 %r30 <- %arg1, %r29 fcmpune.1 %r33 <- %arg2, %r29 or.1 %r34 <- %r30, %r33 @@ -72,18 +71,17 @@ ifior: bfand: .L12: <entry-point> - setfval.32 %r38 <- 0.000000 + setfval.32 %r38 <- 0.000000e+00 fcmpune.1 %r39 <- %arg1, %r38 fcmpune.1 %r42 <- %arg2, %r38 and.1 %r43 <- %r39, %r42 - setne.1 %r45 <- %r43, $0 - ret.1 %r45 + ret.1 %r43 ifand: .L14: <entry-point> - setfval.32 %r48 <- 0.000000 + setfval.32 %r48 <- 0.000000e+00 fcmpune.1 %r49 <- %arg1, %r48 fcmpune.1 %r52 <- %arg2, %r48 and.1 %r53 <- %r49, %r52 diff --git a/validation/optim/bool-sext-test.c b/validation/optim/bool-sext-test.c new file mode 100644 index 00000000..bd85e06e --- /dev/null +++ b/validation/optim/bool-sext-test.c @@ -0,0 +1,12 @@ +_Bool eqs0( signed char a) { return a == 0; } +_Bool eqs1( signed char a) { return a == 1; } +_Bool nes0( signed char a) { return a != 0; } +_Bool nes1( signed char a) { return a != 1; } + +/* + * check-name: bool-sext-test + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: sext\\. + */ diff --git a/validation/optim/bool-simplify.c b/validation/optim/bool-simplify.c index 68aabb78..fe8ce88b 100644 --- a/validation/optim/bool-simplify.c +++ b/validation/optim/bool-simplify.c @@ -43,17 +43,15 @@ and_0: and_1: .L2: <entry-point> - setne.1 %r8 <- %arg1, $0 - zext.32 %r11 <- (1) %r8 - ret.32 %r11 + setne.32 %r9 <- %arg1, $0 + ret.32 %r9 or_0: .L4: <entry-point> - setne.1 %r14 <- %arg1, $0 - zext.32 %r17 <- (1) %r14 - ret.32 %r17 + setne.32 %r14 <- %arg1, $0 + ret.32 %r14 or_1: @@ -65,9 +63,8 @@ or_1: and_2: .L8: <entry-point> - setne.1 %r26 <- %arg1, $0 - zext.32 %r29 <- (1) %r26 - ret.32 %r29 + setne.32 %r25 <- %arg1, $0 + ret.32 %r25 or_2: diff --git a/validation/optim/bool-simplify2.c b/validation/optim/bool-simplify2.c index c94b4412..a089fe62 100644 --- a/validation/optim/bool-simplify2.c +++ b/validation/optim/bool-simplify2.c @@ -27,7 +27,7 @@ static bool babbb(bool a, bool b, bool c) { return a && b && c; } * check-name: bool-simplify2 * check-command: test-linearize $file * - * check-output-pattern(36): setne\\. + * check-output-pattern(20): setne\\. * check-output-pattern(4): seteq\\. * check-output-pattern(8): zext\\. * check-output-pattern(12): and @@ -75,8 +75,7 @@ boii: setne.1 %r23 <- %arg1, $0 setne.1 %r25 <- %arg2, $0 or.1 %r26 <- %r23, %r25 - setne.1 %r28 <- %r26, $0 - ret.1 %r28 + ret.1 %r26 baii: @@ -85,8 +84,7 @@ baii: setne.1 %r31 <- %arg1, $0 setne.1 %r33 <- %arg2, $0 and.1 %r34 <- %r31, %r33 - setne.1 %r36 <- %r34, $0 - ret.1 %r36 + ret.1 %r34 ioiii: @@ -95,9 +93,8 @@ ioiii: setne.1 %r39 <- %arg1, $0 setne.1 %r41 <- %arg2, $0 or.1 %r42 <- %r39, %r41 - setne.1 %r44 <- %r42, $0 setne.1 %r46 <- %arg3, $0 - or.1 %r47 <- %r44, %r46 + or.1 %r47 <- %r42, %r46 zext.32 %r48 <- (1) %r47 ret.32 %r48 @@ -108,9 +105,8 @@ iaiii: setne.1 %r51 <- %arg1, $0 setne.1 %r53 <- %arg2, $0 and.1 %r54 <- %r51, %r53 - setne.1 %r56 <- %r54, $0 setne.1 %r58 <- %arg3, $0 - and.1 %r59 <- %r56, %r58 + and.1 %r59 <- %r54, %r58 zext.32 %r60 <- (1) %r59 ret.32 %r60 @@ -121,11 +117,9 @@ boiii: setne.1 %r63 <- %arg1, $0 setne.1 %r65 <- %arg2, $0 or.1 %r66 <- %r63, %r65 - setne.1 %r68 <- %r66, $0 setne.1 %r70 <- %arg3, $0 - or.1 %r71 <- %r68, %r70 - setne.1 %r73 <- %r71, $0 - ret.1 %r73 + or.1 %r71 <- %r66, %r70 + ret.1 %r71 baiii: @@ -134,11 +128,9 @@ baiii: setne.1 %r76 <- %arg1, $0 setne.1 %r78 <- %arg2, $0 and.1 %r79 <- %r76, %r78 - setne.1 %r81 <- %r79, $0 setne.1 %r83 <- %arg3, $0 - and.1 %r84 <- %r81, %r83 - setne.1 %r86 <- %r84, $0 - ret.1 %r86 + and.1 %r84 <- %r79, %r83 + ret.1 %r84 inb: @@ -175,24 +167,21 @@ bobb: .L28: <entry-point> or.1 %r107 <- %arg1, %arg2 - setne.1 %r109 <- %r107, $0 - ret.1 %r109 + ret.1 %r107 babb: .L30: <entry-point> and.1 %r113 <- %arg1, %arg2 - setne.1 %r115 <- %r113, $0 - ret.1 %r115 + ret.1 %r113 iobbb: .L32: <entry-point> or.1 %r119 <- %arg1, %arg2 - setne.1 %r121 <- %r119, $0 - or.1 %r123 <- %r121, %arg3 + or.1 %r123 <- %r119, %arg3 zext.32 %r124 <- (1) %r123 ret.32 %r124 @@ -201,8 +190,7 @@ iabbb: .L34: <entry-point> and.1 %r128 <- %arg1, %arg2 - setne.1 %r130 <- %r128, $0 - and.1 %r132 <- %r130, %arg3 + and.1 %r132 <- %r128, %arg3 zext.32 %r133 <- (1) %r132 ret.32 %r133 @@ -211,20 +199,16 @@ bobbb: .L36: <entry-point> or.1 %r137 <- %arg1, %arg2 - setne.1 %r139 <- %r137, $0 - or.1 %r141 <- %r139, %arg3 - setne.1 %r143 <- %r141, $0 - ret.1 %r143 + or.1 %r141 <- %r137, %arg3 + ret.1 %r141 babbb: .L38: <entry-point> and.1 %r147 <- %arg1, %arg2 - setne.1 %r149 <- %r147, $0 - and.1 %r151 <- %r149, %arg3 - setne.1 %r153 <- %r151, $0 - ret.1 %r153 + and.1 %r151 <- %r147, %arg3 + ret.1 %r151 * check-output-end diff --git a/validation/optim/bool-zext-test.c b/validation/optim/bool-zext-test.c new file mode 100644 index 00000000..138938b0 --- /dev/null +++ b/validation/optim/bool-zext-test.c @@ -0,0 +1,12 @@ +_Bool equ0(unsigned char a) { return a == 0; } +_Bool equ1(unsigned char a) { return a == 1; } +_Bool neu0(unsigned char a) { return a != 0; } +_Bool neu1(unsigned char a) { return a != 1; } + +/* + * check-name: bool-zext-test + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: zext\\. + */ diff --git a/validation/optim/call-inlined.c b/validation/optim/call-inlined.c index 00698a4b..f21b3294 100644 --- a/validation/optim/call-inlined.c +++ b/validation/optim/call-inlined.c @@ -22,8 +22,8 @@ int foo(int a, int b, int p) foo: .L0: <entry-point> - select.32 %r9 <- %arg3, %arg3, $0 - ret.32 %r9 + select.32 %r10 <- %arg3, %arg3, $0 + ret.32 %r10 * check-output-end diff --git a/validation/linear/cast-kinds.c b/validation/optim/cast-kinds.c index 5df307bc..b144dc7e 100644 --- a/validation/linear/cast-kinds.c +++ b/validation/optim/cast-kinds.c @@ -88,8 +88,7 @@ vptr_2_int: iptr_2_int: .L8: <entry-point> - ptrtu.64 %r13 <- (64) %arg1 - trunc.32 %r14 <- (64) %r13 + trunc.32 %r14 <- (64) %arg1 ret.32 %r14 @@ -137,8 +136,7 @@ vptr_2_uint: iptr_2_uint: .L22: <entry-point> - ptrtu.64 %r34 <- (64) %arg1 - trunc.32 %r35 <- (64) %r34 + trunc.32 %r35 <- (64) %arg1 ret.32 %r35 @@ -185,8 +183,7 @@ vptr_2_long: iptr_2_long: .L36: <entry-point> - ptrtu.64 %r54 <- (64) %arg1 - ret.64 %r54 + ret.64 %arg1 float_2_long: @@ -232,8 +229,7 @@ vptr_2_ulong: iptr_2_ulong: .L50: <entry-point> - ptrtu.64 %r73 <- (64) %arg1 - ret.64 %r73 + ret.64 %arg1 float_2_ulong: @@ -286,30 +282,26 @@ int_2_iptr: .L66: <entry-point> sext.64 %r94 <- (32) %arg1 - utptr.64 %r95 <- (64) %r94 - ret.64 %r95 + ret.64 %r94 uint_2_iptr: .L68: <entry-point> zext.64 %r98 <- (32) %arg1 - utptr.64 %r99 <- (64) %r98 - ret.64 %r99 + ret.64 %r98 long_2_iptr: .L70: <entry-point> - utptr.64 %r102 <- (64) %arg1 - ret.64 %r102 + ret.64 %arg1 ulong_2_iptr: .L72: <entry-point> - utptr.64 %r105 <- (64) %arg1 - ret.64 %r105 + ret.64 %arg1 vptr_2_iptr: diff --git a/validation/optim/cast-nop.c b/validation/optim/cast-nop.c new file mode 100644 index 00000000..7741b7a7 --- /dev/null +++ b/validation/optim/cast-nop.c @@ -0,0 +1,18 @@ +static long p2l(long *p) +{ + return (long) p; +} + +static long *l2p(long l) +{ + return (long*)l; +} + +/* + * check-name: cast-nop + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: utptr\\. + * check-output-excludes: ptrtu\\. + */ diff --git a/validation/optim/cse-cmp-next.c b/validation/optim/cse-cmp-next.c new file mode 100644 index 00000000..50fdbac0 --- /dev/null +++ b/validation/optim/cse-cmp-next.c @@ -0,0 +1,15 @@ +void foo(int p, int i, int f, int *ref, int *dst, int *src) +{ + if (p) + f = ref[i]; + if (f) + dst[i] = src[i]; +} + +/* + * check-name: cse-cmp-next + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(1,2): mul\\. + */ diff --git a/validation/optim/ext-trunc-greater.c b/validation/optim/ext-trunc-greater.c new file mode 100644 index 00000000..b682fc5d --- /dev/null +++ b/validation/optim/ext-trunc-greater.c @@ -0,0 +1,17 @@ +short sgt(char x) +{ + return (int) x; +} + +short ugt(unsigned char x) +{ + return (int) x; +} + +/* + * check-name: ext-trunc-greater + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: trunc\\. + */ diff --git a/validation/optim/ext-trunc-same.c b/validation/optim/ext-trunc-same.c new file mode 100644 index 00000000..2bfcf030 --- /dev/null +++ b/validation/optim/ext-trunc-same.c @@ -0,0 +1,19 @@ +short seq(short x) +{ + return (int) x; +} + +short ueq(unsigned short x) +{ + return (int) x; +} + +/* + * check-name: ext-trunc-same + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: trunc\\. + * check-output-excludes: sext\\. + * check-output-excludes: zext\\. + */ diff --git a/validation/optim/ext-trunc-smaller.c b/validation/optim/ext-trunc-smaller.c new file mode 100644 index 00000000..194c98d7 --- /dev/null +++ b/validation/optim/ext-trunc-smaller.c @@ -0,0 +1,18 @@ +char slt(short x) +{ + return (int) x; +} + +char ult(unsigned short x) +{ + return (int) x; +} + +/* + * check-name: ext-trunc-smaller + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: sext\\. + * check-output-excludes: zext\\. + */ diff --git a/validation/optim/lsr-and0.c b/validation/optim/lsr-and0.c new file mode 100644 index 00000000..94310ba8 --- /dev/null +++ b/validation/optim/lsr-and0.c @@ -0,0 +1,13 @@ +unsigned lsr_and0(unsigned x) +{ + unsigned t = (x & 0x00000fff); + return (t >> 12) & t; +} + +/* + * check-name: lsr-and0 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: ret\\..*\\$0$ + */ diff --git a/validation/optim/lsr-and1.c b/validation/optim/lsr-and1.c new file mode 100644 index 00000000..393679e3 --- /dev/null +++ b/validation/optim/lsr-and1.c @@ -0,0 +1,18 @@ +// If (t >> S) is simplified into (x >> S) +// then the whole expression will be 0. +// The test is only interesting if the sub-expression +// (x & M) is referenced more than once +// (because otherwise other simplifications apply). +unsigned lsr_and1(unsigned x) +{ + unsigned t = (x & 0xfffff000); + return ((t >> 12) ^ (x >> 12)) & t; +} + +/* + * check-name: lsr-and1 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: ret\\..*\\$0$ + */ diff --git a/validation/optim/lsr-asr.c b/validation/optim/lsr-asr.c new file mode 100644 index 00000000..aee46940 --- /dev/null +++ b/validation/optim/lsr-asr.c @@ -0,0 +1,42 @@ +int lsrasr0(unsigned int x) +{ + return ((int) (x >> 15)) >> 15; +} + +int lsrasr1(unsigned int x) +{ + return ((int) (x >> 16)) >> 15; +} + +int lsrasr2(unsigned int x) +{ + return ((int) (x >> 16)) >> 16; +} + +/* + * check-name: lsr-asr + * check-command: test-linearize -Wno-decl $file + * + * check-output-start +lsrasr0: +.L0: + <entry-point> + lsr.32 %r3 <- %arg1, $30 + ret.32 %r3 + + +lsrasr1: +.L2: + <entry-point> + lsr.32 %r7 <- %arg1, $31 + ret.32 %r7 + + +lsrasr2: +.L4: + <entry-point> + ret.32 $0 + + + * check-output-end + */ diff --git a/validation/optim/lsr-shl0.c b/validation/optim/lsr-shl0.c new file mode 100644 index 00000000..952baa6b --- /dev/null +++ b/validation/optim/lsr-shl0.c @@ -0,0 +1,14 @@ +unsigned mask(unsigned x) +{ + return (x << 15) >> 15; +} + +/* + * check-name: lsr-shl0 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: and\\..*0x1ffff + * check-output-excludes: lsr\\. + * check-output-excludes: shl\\. + */ diff --git a/validation/optim/mask-lsr.c b/validation/optim/mask-lsr.c new file mode 100644 index 00000000..ec636444 --- /dev/null +++ b/validation/optim/mask-lsr.c @@ -0,0 +1,14 @@ +// ((x & M) | y) >> S to (y >> S) when (M >> S) == 0 + +unsigned int foo(unsigned int x, unsigned int y) +{ + return ((x & 0xff) | y) >> 8; +} + +/* + * check-name: mask-lsr + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: %arg1 + */ diff --git a/validation/optim/mask-out.c b/validation/optim/mask-out.c new file mode 100644 index 00000000..ac85aec8 --- /dev/null +++ b/validation/optim/mask-out.c @@ -0,0 +1,12 @@ +unsigned mask(unsigned a, unsigned b) +{ + return ((a & 0xffff0000) | b) & 0x0000ffff; +} + +/* + * check-name: mask-out + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: %arg1 + */ diff --git a/validation/optim/mask1-setne0.c b/validation/optim/mask1-setne0.c new file mode 100644 index 00000000..1e599dc8 --- /dev/null +++ b/validation/optim/mask1-setne0.c @@ -0,0 +1,28 @@ +struct s { + unsigned i:1; +}; + +int foo(struct s x) +{ + unsigned int i = x.i; + + if (i == 0) + return 1; + else if (i == 1) + return 1; + return 0; +} + +/* + * check-name: mask1-setne0 + * check-command: test-linearize -Wno-decl $file + * + * check-output-start +foo: +.L0: + <entry-point> + ret.32 $1 + + + * check-output-end + */ diff --git a/validation/optim/or-and-constant1.c b/validation/optim/or-and-constant1.c new file mode 100644 index 00000000..aa673b90 --- /dev/null +++ b/validation/optim/or-and-constant1.c @@ -0,0 +1,29 @@ +unsigned int and_or_equ(unsigned int a) +{ + return (a | 3) & 3; +} + +int and_or_eqs(int a) +{ + return (a | 3) & 3; +} + +unsigned int or_and_equ(unsigned int a) +{ + return (a & 3) | 3; +} + +int or_and_eqs(int a) +{ + return (a & 3) | 3; +} + +/* + * check-name: or-and-constant1 + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-pattern(4): ret\\..*\\$3 + * check-output-excludes: or\\. + */ diff --git a/validation/optim/setcc-mask.c b/validation/optim/setcc-mask.c new file mode 100644 index 00000000..5d271788 --- /dev/null +++ b/validation/optim/setcc-mask.c @@ -0,0 +1,18 @@ +int foo (int a) +{ + return ((a == 0) & 1) == (a == 0); +} + +/* + * check-name: setcc-mask + * check-command: test-linearize -Wno-decl $file + * + * check-output-start +foo: +.L0: + <entry-point> + ret.32 $1 + + + * check-output-end + */ diff --git a/validation/optim/setne0-sext.c b/validation/optim/setne0-sext.c new file mode 100644 index 00000000..4167979b --- /dev/null +++ b/validation/optim/setne0-sext.c @@ -0,0 +1,9 @@ +long foo(int a) { return a != 0; } + +/* + * check-name: setne0-sext + * check-command: test-linearize -m64 -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: sext\\. + */ diff --git a/validation/optim/setne0-trunc.c b/validation/optim/setne0-trunc.c new file mode 100644 index 00000000..6c5494ec --- /dev/null +++ b/validation/optim/setne0-trunc.c @@ -0,0 +1,9 @@ +char foo(int a) { return a != 0; } + +/* + * check-name: setne0-trunc + * check-command: test-linearize -m64 -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: trunc\\. + */ diff --git a/validation/optim/setne0-zext.c b/validation/optim/setne0-zext.c new file mode 100644 index 00000000..8a074f03 --- /dev/null +++ b/validation/optim/setne0-zext.c @@ -0,0 +1,9 @@ +unsigned long foo(int a) { return (unsigned int) (a != 0); } + +/* + * check-name: setne0-zext + * check-command: test-linearize -m64 -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: zext\\. + */ diff --git a/validation/optim/sext-sext.c b/validation/optim/sext-sext.c new file mode 100644 index 00000000..604a7dd4 --- /dev/null +++ b/validation/optim/sext-sext.c @@ -0,0 +1,12 @@ +int foo(signed char offset) +{ + return (int)(short) offset; +} + +/* + * check-name: sext-sext + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(1): sext\\. + */ diff --git a/validation/optim/sext.c b/validation/optim/sext.c new file mode 100644 index 00000000..719730d5 --- /dev/null +++ b/validation/optim/sext.c @@ -0,0 +1,15 @@ +int sext(int x) +{ + return (x << 5) >> 5; +} + +/* + * check-name: sext + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-contains: sext\\.$27 + * check-output-excludes: asr\\. + * check-output-excludes: shl\\. + */ diff --git a/validation/optim/sh-or-and0.c b/validation/optim/sh-or-and0.c new file mode 100644 index 00000000..02f0cb03 --- /dev/null +++ b/validation/optim/sh-or-and0.c @@ -0,0 +1,20 @@ +unsigned lsr_or_and0(unsigned x, unsigned b) +{ + return (((x & 0x00000fff) | b) >> 12); +} + +unsigned shl_or_and0(unsigned x, unsigned b) +{ + return (((x & 0xfff00000) | b) << 12); +} + +/* + * check-name: sh-or-and0 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(1): lsr\\. + * check-output-pattern(1): shl\\. + * check-output-excludes: or\\. + * check-output-excludes: and\\. + */ diff --git a/validation/optim/sh-or-and1.c b/validation/optim/sh-or-and1.c new file mode 100644 index 00000000..7b79bbf3 --- /dev/null +++ b/validation/optim/sh-or-and1.c @@ -0,0 +1,20 @@ +unsigned lsr_or_and1(unsigned x, unsigned b) +{ + return (((x & 0xfffff000) | b) >> 12); +} + +unsigned shl_or_and1(unsigned x, unsigned b) +{ + return (((x & 0x000fffff) | b) << 12); +} + +/* + * check-name: sh-or-and1 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(1): lsr\\. + * check-output-pattern(1): shl\\. + * check-output-pattern(2): or\\. + * check-output-excludes: and\\. + */ diff --git a/validation/optim/sh-or-and2.c b/validation/optim/sh-or-and2.c new file mode 100644 index 00000000..241aeaff --- /dev/null +++ b/validation/optim/sh-or-and2.c @@ -0,0 +1,21 @@ +unsigned lsr_or_and2(unsigned x, unsigned b) +{ + return (((x & 0xf0ffffff) | b) >> 12); +} + +unsigned shl_or_and2(unsigned x, unsigned b) +{ + return (((x & 0xffffff0f) | b) << 12); +} + +/* + * check-name: sh-or-and2 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(1): lsr\\. + * check-output-pattern(1): shl\\. + * check-output-pattern(2): or\\. + * check-output-pattern(1): and\\..*\\$0xf0fff000 + * check-output-pattern(1): and\\..*\\$0xfff0f + */ diff --git a/validation/optim/shift-big.c b/validation/optim/shift-big.c new file mode 100644 index 00000000..84bcd2ce --- /dev/null +++ b/validation/optim/shift-big.c @@ -0,0 +1,82 @@ +typedef unsigned int u32; +typedef int s32; + +s32 asr31(s32 a) { return a >> 31; } +s32 asr32(s32 a) { return a >> 32; } +s32 asr33(s32 a) { return a >> 33; } + +u32 lsr31(u32 a) { return a >> 31; } +u32 lsr32(u32 a) { return a >> 32; } +u32 lsr33(u32 a) { return a >> 33; } + +u32 shl31(u32 a) { return a << 31; } +u32 shl32(u32 a) { return a << 32; } +u32 shl33(u32 a) { return a << 33; } + +/* + * check-name: optim/shift-big.c + * check-command: test-linearize -Wno-decl -m64 $file + * + * check-error-ignore + * check-output-start +asr31: +.L0: + <entry-point> + asr.32 %r2 <- %arg1, $31 + ret.32 %r2 + + +asr32: +.L2: + <entry-point> + asr.32 %r5 <- %arg1, $32 + ret.32 %r5 + + +asr33: +.L4: + <entry-point> + asr.32 %r8 <- %arg1, $33 + ret.32 %r8 + + +lsr31: +.L6: + <entry-point> + lsr.32 %r11 <- %arg1, $31 + ret.32 %r11 + + +lsr32: +.L8: + <entry-point> + ret.32 $0 + + +lsr33: +.L10: + <entry-point> + ret.32 $0 + + +shl31: +.L12: + <entry-point> + shl.32 %r20 <- %arg1, $31 + ret.32 %r20 + + +shl32: +.L14: + <entry-point> + ret.32 $0 + + +shl33: +.L16: + <entry-point> + ret.32 $0 + + + * check-output-end + */ diff --git a/validation/optim/shift-shift.c b/validation/optim/shift-shift.c new file mode 100644 index 00000000..12a4b7d4 --- /dev/null +++ b/validation/optim/shift-shift.c @@ -0,0 +1,149 @@ +unsigned int shl0(unsigned int x) +{ + return x << 15 << 15; +} + +unsigned int shl1(unsigned int x) +{ + return x << 16 << 15; +} + +unsigned int shl2(unsigned int x) +{ + return x << 16 << 16; +} + +unsigned int shl3(unsigned int x) +{ + return x << 12 << 10 << 10; +} + + +unsigned int lsr0(unsigned int x) +{ + return x >> 15 >> 15; +} + +unsigned int lsr1(unsigned int x) +{ + return x >> 16 >> 15; +} + +unsigned int lsr2(unsigned int x) +{ + return x >> 16 >> 16; +} + +unsigned int lsr3(unsigned int x) +{ + return x >> 12 >> 10 >> 10; +} + + +int asr0(int x) +{ + return x >> 15 >> 15; +} + +int asr1(int x) +{ + return x >> 16 >> 15; +} + +int asr2(int x) +{ + return x >> 16 >> 16; +} + +int asr3(int x) +{ + return x >> 12 >> 10 >> 10; +} + +/* + * check-name: shift-shift + * check-command: test-linearize -Wno-decl $file + * + * check-output-start +shl0: +.L0: + <entry-point> + shl.32 %r3 <- %arg1, $30 + ret.32 %r3 + + +shl1: +.L2: + <entry-point> + shl.32 %r7 <- %arg1, $31 + ret.32 %r7 + + +shl2: +.L4: + <entry-point> + ret.32 $0 + + +shl3: +.L6: + <entry-point> + ret.32 $0 + + +lsr0: +.L8: + <entry-point> + lsr.32 %r20 <- %arg1, $30 + ret.32 %r20 + + +lsr1: +.L10: + <entry-point> + lsr.32 %r24 <- %arg1, $31 + ret.32 %r24 + + +lsr2: +.L12: + <entry-point> + ret.32 $0 + + +lsr3: +.L14: + <entry-point> + ret.32 $0 + + +asr0: +.L16: + <entry-point> + asr.32 %r37 <- %arg1, $30 + ret.32 %r37 + + +asr1: +.L18: + <entry-point> + asr.32 %r41 <- %arg1, $31 + ret.32 %r41 + + +asr2: +.L20: + <entry-point> + asr.32 %r45 <- %arg1, $31 + ret.32 %r45 + + +asr3: +.L22: + <entry-point> + asr.32 %r50 <- %arg1, $31 + ret.32 %r50 + + + * check-output-end + */ diff --git a/validation/optim/shift-zext.c b/validation/optim/shift-zext.c new file mode 100644 index 00000000..30409bec --- /dev/null +++ b/validation/optim/shift-zext.c @@ -0,0 +1,12 @@ +unsigned int foo(unsigned int x) +{ + return (x << 20) >> 20; +} + +/* + * check-name: shift-zext + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: and\\..*%arg1, \\$0xfff + */ diff --git a/validation/optim/shl-and0.c b/validation/optim/shl-and0.c new file mode 100644 index 00000000..894bd882 --- /dev/null +++ b/validation/optim/shl-and0.c @@ -0,0 +1,13 @@ +unsigned shl_and0(unsigned x) +{ + unsigned t = (x & 0xfff00000); + return (t << 12) & t; +} + +/* + * check-name: shl-and0 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: ret\\..*\\$0$ + */ diff --git a/validation/optim/shl-and1.c b/validation/optim/shl-and1.c new file mode 100644 index 00000000..13a1675b --- /dev/null +++ b/validation/optim/shl-and1.c @@ -0,0 +1,18 @@ +// If (t << S) is simplified into (x << S) +// then the whole expression will be 0. +// The test is only interesting if the sub-expression +// (x & M) is referenced more than once +// (because otherwise other simplifications apply). +unsigned shl_and1(unsigned x) +{ + unsigned t = (x & 0x000fffff); + return ((t << 12) ^ (x << 12)) & t; +} + +/* + * check-name: shl-and1 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: ret\\..*\\$0$ + */ diff --git a/validation/optim/shl-lsr0.c b/validation/optim/shl-lsr0.c new file mode 100644 index 00000000..fc2561bd --- /dev/null +++ b/validation/optim/shl-lsr0.c @@ -0,0 +1,14 @@ +unsigned mask(unsigned x) +{ + return (x >> 15) << 15; +} + +/* + * check-name: shl-lsr0 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: and\\..*0xffff8000 + * check-output-excludes: lsr\\. + * check-output-excludes: shl\\. + */ diff --git a/validation/optim/trunc-mask-zext.c b/validation/optim/trunc-mask-zext.c new file mode 100644 index 00000000..9b604174 --- /dev/null +++ b/validation/optim/trunc-mask-zext.c @@ -0,0 +1,13 @@ +unsigned long long foo(unsigned long long x) +{ + return (((unsigned int) x) & 0x7ffU); +} + +/* + * check-name: trunc-mask-zext + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: trunc\\. + * check-output-excludes: zext\\. + */ diff --git a/validation/optim/trunc-or-shl.c b/validation/optim/trunc-or-shl.c new file mode 100644 index 00000000..70d8bd1d --- /dev/null +++ b/validation/optim/trunc-or-shl.c @@ -0,0 +1,13 @@ +char foo(int a, int b) +{ + return (a << 8) | b; +} + +/* + * check-name: trunc-or-shl + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-contains: ret\\..*%arg2 + */ diff --git a/validation/optim/trunc-seteq0.c b/validation/optim/trunc-seteq0.c new file mode 100644 index 00000000..5994b17c --- /dev/null +++ b/validation/optim/trunc-seteq0.c @@ -0,0 +1,18 @@ +struct S { + int :1; + signed int s:2; + unsigned int u:3; +}; + +int os(int i, struct S *b) { return i || b->s; } +int ou(int i, struct S *b) { return i || b->u; } + +/* + * check-name: trunc-seteq0 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: trunc\\. + * check-output-excludes: sext\\. + * check-output-excludes: zext\\. + */ diff --git a/validation/optim/trunc-setne0.c b/validation/optim/trunc-setne0.c new file mode 100644 index 00000000..878c05fa --- /dev/null +++ b/validation/optim/trunc-setne0.c @@ -0,0 +1,20 @@ +struct s { + unsigned int u:1; +}; + +unsigned int foo(struct s x) +{ + if (x.u) + return 1; + else + return 0; +} + +/* + * check-name: trunc-setne0 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: and\\. + * check-output-excludes: trunc\\. + */ diff --git a/validation/optim/trunc-trunc.c b/validation/optim/trunc-trunc.c new file mode 100644 index 00000000..6dc50aee --- /dev/null +++ b/validation/optim/trunc-trunc.c @@ -0,0 +1,12 @@ +char foo(int a) +{ + return ((((short) a) + 1) - 1); +} + +/* + * check-name: trunc-trunc + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern(1): trunc\\. + */ diff --git a/validation/optim/zext-and.c b/validation/optim/zext-and.c new file mode 100644 index 00000000..a3153bf7 --- /dev/null +++ b/validation/optim/zext-and.c @@ -0,0 +1,12 @@ +unsigned int foo(unsigned char x) +{ + return (unsigned int)x & 0xffffU; +} + +/* + * check-name: zext-and + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: and\\. + */ diff --git a/validation/optim/zext-and1.c b/validation/optim/zext-and1.c new file mode 100644 index 00000000..c99a0e62 --- /dev/null +++ b/validation/optim/zext-and1.c @@ -0,0 +1,12 @@ +unsigned int bar(unsigned char x) +{ + return (unsigned int)x & 0xff01U; +} + +/* + * check-name: zext-and1 + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: and\\..*\\$1 + */ diff --git a/validation/optim/zext-asr.c b/validation/optim/zext-asr.c new file mode 100644 index 00000000..5f235ad8 --- /dev/null +++ b/validation/optim/zext-asr.c @@ -0,0 +1,13 @@ +unsigned short foo(unsigned short a) +{ + return a >> 16; +} + +/* + * check-name: zext-asr + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-contains: ret\\..*\\$0 + * check-output-excludes: asr\\. + */ diff --git a/validation/optim/zext-sext.c b/validation/optim/zext-sext.c new file mode 100644 index 00000000..1fe3900d --- /dev/null +++ b/validation/optim/zext-sext.c @@ -0,0 +1,13 @@ +int foo(unsigned char offset) +{ + return (int)(short) offset; +} + +/* + * check-name: zext-sext + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: sext\\. + * check-output-pattern(1): zext\\. + */ diff --git a/validation/optim/zext-zext.c b/validation/optim/zext-zext.c new file mode 100644 index 00000000..986d2242 --- /dev/null +++ b/validation/optim/zext-zext.c @@ -0,0 +1,13 @@ +int foo(unsigned char offset) +{ + return (int)(unsigned short) offset; +} + +/* + * check-name: zext-zext + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: sext\\. + * check-output-pattern(1): zext\\. + */ diff --git a/validation/shift-negative.c b/validation/shift-negative.c new file mode 100644 index 00000000..fff5cf12 --- /dev/null +++ b/validation/shift-negative.c @@ -0,0 +1,17 @@ +unsigned int fn1(unsigned int a) { return a >> -1; } +unsigned int fn2(unsigned int a) { return a >> ~0; } + +unsigned int fo1(unsigned int a) { return a >> ((a & 0) | -1); } +unsigned int fo2(unsigned int a) { return a >> ((a & 0) ^ ~0); } + +/* + * check-name: shift-negative + * check-command: sparse -Wno-decl $file + * + * check-error-start +shift-negative.c:1:45: warning: shift count is negative (-1) +shift-negative.c:2:45: warning: shift count is negative (-1) +shift-negative.c:4:59: warning: shift count is negative (-1) +shift-negative.c:5:59: warning: shift count is negative (-1) + * check-error-end + */ diff --git a/validation/shift-undef-long.c b/validation/shift-undef-long.c new file mode 100644 index 00000000..32626743 --- /dev/null +++ b/validation/shift-undef-long.c @@ -0,0 +1,21 @@ +static unsigned very_big_shift(unsigned int a) +{ + unsigned r = 0; + r |= a << (0ULL ^ ~0U); + r |= a << ((( signed long long) ~0U) + 1); + r |= a << (((unsigned long long) ~0U) + 1); + r |= a << (~((unsigned long long) ~0U)); + return r; +} + +/* + * check-name: shift-undef-long + * check-command: sparse -m64 $file + * + * check-error-start +shift-undef-long.c:4:16: warning: shift too big (4294967295) for type unsigned int +shift-undef-long.c:5:16: warning: shift too big (4294967296) for type unsigned int +shift-undef-long.c:6:16: warning: shift too big (4294967296) for type unsigned int +shift-undef-long.c:7:16: warning: shift count is negative (-4294967296) + * check-error-end + */ diff --git a/validation/shift-undef.c b/validation/shift-undef.c new file mode 100644 index 00000000..4e94fa23 --- /dev/null +++ b/validation/shift-undef.c @@ -0,0 +1,164 @@ +int simple(int s, unsigned int u, int p) +{ + s = s >> 100; + u = u >> 101; + u = u << 102; + s = s >> -1; + u = u >> -2; + u = u << -3; + if (0) return s >> 103; + if (0) return u >> 104; + if (0) return u << 105; + if (0) return s >> -4; + if (0) return u >> -5; + if (0) return u << -6; + if (p && 0) return s >> 106; + if (p && 0) return u >> 107; + if (p && 0) return u << 108; + if (p && 0) return s >> -7; + if (p && 0) return u >> -8; + if (p && 0) return u << -9; + s = s >> ((p & 0) + 109); u ^= p; // reloaded because now == 0 + u = u >> ((p & 0) + 110); u ^= p; // reloaded because now == 0 + u = u << ((p & 0) + 111); u ^= p; // reloaded because now == 0 + s = s >> ((p & 0) + -10); + u = u >> ((p & 0) + -11); u ^= p; // reloaded because now == 0 + u = u << ((p & 0) + -12); u ^= p; // reloaded because now == 0 + return s + u; +} + +int compound(int s, unsigned int u, int p) +{ + s >>= 100; + u >>= 101; + u <<= 102; + s >>= -1; + u >>= -2; + u <<= -3; + if (0) return s >>= 103; + if (0) return u >>= 104; + if (0) return u <<= 105; + if (0) return s >>= -4; + if (0) return u >>= -5; + if (0) return u <<= -6; + if (p && 0) return s >>= 106; + if (p && 0) return u >>= 107; + if (p && 0) return u <<= 108; + if (p && 0) return s >>= -7; + if (p && 0) return u >>= -8; + if (p && 0) return u <<= -9; + s >>= ((p & 0) + 109); u ^= p; // reloaded because now == 0 + u >>= ((p & 0) + 110); u ^= p; // reloaded because now == 0 + u <<= ((p & 0) + 111); u ^= p; // reloaded because now == 0 + s >>= ((p & 0) + -10); + u >>= ((p & 0) + -11); u ^= p; // reloaded because now == 0 + u <<= ((p & 0) + -12); u ^= p; // reloaded because now == 0 + return s + u; +} + +int ok(int s, unsigned int u, int p) +{ + // GCC doesn't warn on these + if (0 && (s >> 100)) return 0; + if (0 && (u >> 101)) return 0; + if (0 && (u << 102)) return 0; + if (0 && (s >> -1)) return 0; + if (0 && (u >> -2)) return 0; + if (0 && (u << -3)) return 0; + if (0 && (s >>= 103)) return 0; + if (0 && (u >>= 104)) return 0; + if (0 && (u <<= 105)) return 0; + if (0 && (s >>= -4)) return 0; + if (0 && (u >>= -5)) return 0; + if (0 && (u <<= -6)) return 0; + return 1; +} + +struct bf { + unsigned int u:8; + int s:8; +}; + +int bf(struct bf *p) +{ + unsigned int r = 0; + r += p->s << 8; + r += p->s >> 8; + r += p->u >> 8; + return r; +} + +/* + * The following is used in the kernel at several places + * It shouldn't emit any warnings. + */ +typedef unsigned long long u64; +typedef unsigned int u32; + +extern void hw_w32x2(u32 hi, u32 lo); + +inline void hw_w64(u64 val) +{ + hw_w32x2(val >> 32, (u32) val); +} + +void hw_write(u32 val) +{ + hw_w64(val); +} + +/* + * check-name: shift too big or negative + * check-command: sparse -Wno-decl $file + * + * check-error-start +shift-undef.c:3:15: warning: shift too big (100) for type int +shift-undef.c:4:15: warning: shift too big (101) for type unsigned int +shift-undef.c:5:15: warning: shift too big (102) for type unsigned int +shift-undef.c:6:15: warning: shift count is negative (-1) +shift-undef.c:7:15: warning: shift count is negative (-2) +shift-undef.c:8:15: warning: shift count is negative (-3) +shift-undef.c:9:25: warning: shift too big (103) for type int +shift-undef.c:10:25: warning: shift too big (104) for type unsigned int +shift-undef.c:11:25: warning: shift too big (105) for type unsigned int +shift-undef.c:12:25: warning: shift count is negative (-4) +shift-undef.c:13:25: warning: shift count is negative (-5) +shift-undef.c:14:25: warning: shift count is negative (-6) +shift-undef.c:15:30: warning: shift too big (106) for type int +shift-undef.c:16:30: warning: shift too big (107) for type unsigned int +shift-undef.c:17:30: warning: shift too big (108) for type unsigned int +shift-undef.c:18:30: warning: shift count is negative (-7) +shift-undef.c:19:30: warning: shift count is negative (-8) +shift-undef.c:20:30: warning: shift count is negative (-9) +shift-undef.c:21:29: warning: shift too big (109) for type int +shift-undef.c:22:29: warning: shift too big (110) for type unsigned int +shift-undef.c:23:29: warning: shift too big (111) for type unsigned int +shift-undef.c:24:29: warning: shift count is negative (-10) +shift-undef.c:25:29: warning: shift count is negative (-11) +shift-undef.c:26:29: warning: shift count is negative (-12) +shift-undef.c:32:11: warning: shift too big (100) for type int +shift-undef.c:33:11: warning: shift too big (101) for type unsigned int +shift-undef.c:34:11: warning: shift too big (102) for type unsigned int +shift-undef.c:35:11: warning: shift count is negative (-1) +shift-undef.c:36:11: warning: shift count is negative (-2) +shift-undef.c:37:11: warning: shift count is negative (-3) +shift-undef.c:38:25: warning: shift too big (103) for type int +shift-undef.c:39:25: warning: shift too big (104) for type unsigned int +shift-undef.c:40:25: warning: shift too big (105) for type unsigned int +shift-undef.c:41:25: warning: shift count is negative (-4) +shift-undef.c:42:25: warning: shift count is negative (-5) +shift-undef.c:43:25: warning: shift count is negative (-6) +shift-undef.c:44:30: warning: shift too big (106) for type int +shift-undef.c:45:30: warning: shift too big (107) for type unsigned int +shift-undef.c:46:30: warning: shift too big (108) for type unsigned int +shift-undef.c:47:30: warning: shift count is negative (-7) +shift-undef.c:48:30: warning: shift count is negative (-8) +shift-undef.c:49:30: warning: shift count is negative (-9) +shift-undef.c:50:26: warning: shift too big (109) for type int +shift-undef.c:51:26: warning: shift too big (110) for type int +shift-undef.c:52:26: warning: shift too big (111) for type int +shift-undef.c:53:26: warning: shift count is negative (-10) +shift-undef.c:54:26: warning: shift count is negative (-11) +shift-undef.c:55:26: warning: shift count is negative (-12) + * check-error-end + */ |
