In the mathematical sense, the result of LSR by an amount bigger than the operand size equals zero. Do the corresponding simplification. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- simplify.c | 8 ++++++++ validation/optim/shift-big.c | 27 +++++++++++++++++++++++++++ validation/shift-undef.c | 20 ++++++++++---------- 3 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 validation/optim/shift-big.c diff --git a/simplify.c b/simplify.c index 41e2584a6..9b700abc8 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 000000000..3249854e2 --- /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 4cd56b81c..aba226c19 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; } -- 2.18.0 -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html