aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
-rw-r--r--simplify.c8
-rw-r--r--validation/optim/shift-big.c27
-rw-r--r--validation/shift-undef.c20
3 files changed, 45 insertions, 10 deletions
diff --git a/simplify.c b/simplify.c
index 41e2584a..9b700abc 100644
--- a/simplify.c
+++ b/simplify.c
@@ -552,6 +552,14 @@ static int simplify_shift(struct instruction *insn, pseudo_t pseudo, long long v
warning(insn->pos, "right shift by bigger than source value");
insn->tainted = 1;
}
+ switch (insn->opcode) {
+ case OP_ASR:
+ break;
+ case OP_LSR:
+ size = operand_size(insn, pseudo);
+ if (value >= size)
+ return replace_with_pseudo(insn, value_pseudo(0));
+ }
return 0;
}
diff --git a/validation/optim/shift-big.c b/validation/optim/shift-big.c
new file mode 100644
index 00000000..3249854e
--- /dev/null
+++ b/validation/optim/shift-big.c
@@ -0,0 +1,27 @@
+typedef unsigned int u32;
+typedef int s32;
+
+static u32 lsr32(u32 a) { return a >> 32; }
+static s32 asr32(s32 a) { return a >> 32; }
+
+/*
+ * check-name: optim/shift-big.c
+ * check-command: test-linearize -fnormalize-pseudos $file
+ *
+ * check-error-ignore
+ * check-output-start
+lsr32:
+.L0:
+ <entry-point>
+ ret.32 $0
+
+
+asr32:
+.L2:
+ <entry-point>
+ asr.32 %r5 <- %arg1, $32
+ ret.32 %r5
+
+
+ * check-output-end
+ */
diff --git a/validation/shift-undef.c b/validation/shift-undef.c
index 4cd56b81..aba226c1 100644
--- a/validation/shift-undef.c
+++ b/validation/shift-undef.c
@@ -18,12 +18,12 @@ int simple(int s, unsigned int u, int p)
if (p && 0) return s >> -7;
if (p && 0) return u >> -8;
if (p && 0) return u << -9;
- s = s >> ((p & 0) + 109);
- u = u >> ((p & 0) + 110);
- u = u << ((p & 0) + 111);
+ 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 = u << ((p & 0) + -12);
+ 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;
}
@@ -47,12 +47,12 @@ int compound(int s, unsigned int u, int p)
if (p && 0) return s >>= -7;
if (p && 0) return u >>= -8;
if (p && 0) return u <<= -9;
- s >>= ((p & 0) + 109);
- u >>= ((p & 0) + 110);
- u <<= ((p & 0) + 111);
+ 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 & 0) + -12);
+ u >>= ((p & 0) + -11); u ^= p; // reloaded because now == 0
+ u <<= ((p & 0) + -12); u ^= p; // reloaded because now == 0
return s + u;
}