diff mbox series

testsuite: add testcase for bogus linearization of >>= & /=

Message ID 20200705123850.25924-1-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series testsuite: add testcase for bogus linearization of >>= & /= | expand

Commit Message

Luc Van Oostenryck July 5, 2020, 12:38 p.m. UTC
When doing a shift operation, both arguments are subjected to
integer promotion and the type of the result is simply the type
of the promoted left operand. Easy.

But for a shift-assignment, things are slightly more complex:
  -) 'a >>= n' should be equivalent to 'a = a >> n'
  -) but the type of the result must be the type of the left
     operand *before* integer promotion.

Currently, the linearization code use the type of the right
operand to infer of the type of the operation. But simply changing
the code to use the type of the left operand will also be wrong
(for example for signed/unsigned divisions). Nasty.

For example, the following C code:
	int s = ...;
	s >>= 11U;
is linearized as a logical shift:
	lsr.32      %r2 <- %arg1, $11
while, of course it's an arithmetic shift that is expected:
	asr.32      %r2 <- %arg1, $11

So, add a testcase for these.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/linear/bug-assign-op0.c | 115 +++++++++++++++++++++++++++++
 1 file changed, 115 insertions(+)
 create mode 100644 validation/linear/bug-assign-op0.c
diff mbox series

Patch

diff --git a/validation/linear/bug-assign-op0.c b/validation/linear/bug-assign-op0.c
new file mode 100644
index 000000000000..0cabc6222b8a
--- /dev/null
+++ b/validation/linear/bug-assign-op0.c
@@ -0,0 +1,115 @@ 
+int asr(int s)
+{
+	s >>= 11U;
+	return s;
+}
+
+unsigned int lsr(unsigned int u)
+{
+	u >>= 11;
+	return u;
+}
+
+int divr(int s, unsigned long u)
+{
+	extern int use(int, unsigned);
+	int t = s;
+	s = s / u;
+	u = u / t;
+	return use(s, u);
+}
+
+int sdivul(int s, unsigned long u)
+{
+	s /= u;			// divu
+	return s;
+}
+
+unsigned int udivsl(unsigned int u, long s)
+{
+	u /= s;			// divs
+	return u;
+}
+
+int uldivs(int s, unsigned long u)
+{
+	u /= s;			// divu
+	return u;
+}
+
+unsigned int sldivu(unsigned int u, long s)
+{
+	s /= u;			// divs
+	return s;
+}
+
+/*
+ * check-name: bug-assign-op0
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-start
+asr:
+.L0:
+	<entry-point>
+	asr.32      %r2 <- %arg1, $11
+	ret.32      %r2
+
+
+lsr:
+.L2:
+	<entry-point>
+	lsr.32      %r6 <- %arg1, $11
+	ret.32      %r6
+
+
+divr:
+.L4:
+	<entry-point>
+	sext.64     %r11 <- (32) %arg1
+	divu.64     %r13 <- %r11, %arg2
+	trunc.32    %r14 <- (64) %r13
+	divu.64     %r18 <- %arg2, %r11
+	trunc.32    %r21 <- (64) %r18
+	call.32     %r22 <- use, %r14, %r21
+	ret.32      %r22
+
+
+sdivul:
+.L6:
+	<entry-point>
+	sext.64     %r26 <- (32) %arg1
+	divu.64     %r27 <- %r26, %arg2
+	trunc.32    %r28 <- (64) %r27
+	ret.32      %r28
+
+
+udivsl:
+.L8:
+	<entry-point>
+	zext.64     %r33 <- (32) %arg1
+	divs.64     %r34 <- %r33, %arg2
+	trunc.32    %r35 <- (64) %r34
+	ret.32      %r35
+
+
+uldivs:
+.L10:
+	<entry-point>
+	sext.64     %r39 <- (32) %arg1
+	divu.64     %r41 <- %arg2, %r39
+	trunc.32    %r43 <- (64) %r41
+	ret.32      %r43
+
+
+sldivu:
+.L12:
+	<entry-point>
+	zext.64     %r46 <- (32) %arg1
+	divs.64     %r48 <- %arg2, %r46
+	trunc.32    %r50 <- (64) %r48
+	ret.32      %r50
+
+
+ * check-output-end
+ */