From 05f3fda388756b911406c06368d76fd410d84808 Mon Sep 17 00:00:00 2001 From: Richard Stallman Date: Tue, 26 Oct 1993 08:26:08 +0000 Subject: [PATCH] (build_binary_op): For TRUNC_MOD_EXPR and FLOOR_MOD_EXPR, don't shorten when divisor might be -1. From-SVN: r5893 --- gcc/c-typeck.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 3c6f08bd991..c12f775a050 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -1982,7 +1982,14 @@ build_binary_op (code, orig_op0, orig_op1, convert_p) case TRUNC_MOD_EXPR: case FLOOR_MOD_EXPR: if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) - shorten = 1; + /* Although it would be tempting to shorten always here, doing so loses + on some targets, since the modulo instruction is undefined if the + quotient can't be represented in the computation mode. We shorten + only if unsigned or if dividing by something we know != -1. */ + shorten = (TREE_UNSIGNED (orig_op0) + || (TREE_CODE (op1) == INTEGER_CST + && (TREE_INT_CST_LOW (op1) != -1 + || TREE_INT_CST_HIGH (op1) != -1))); break; case TRUTH_ANDIF_EXPR: -- 2.30.2