summaryrefslogtreecommitdiffstats
path: root/libgfortran/generated/cshift0_i16.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgfortran/generated/cshift0_i16.c')
-rw-r--r--libgfortran/generated/cshift0_i16.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/libgfortran/generated/cshift0_i16.c b/libgfortran/generated/cshift0_i16.c
index 7566042c8fb..b1143032021 100644
--- a/libgfortran/generated/cshift0_i16.c
+++ b/libgfortran/generated/cshift0_i16.c
@@ -97,9 +97,13 @@ cshift0_i16 (gfc_array_i16 *ret, const gfc_array_i16 *array, ptrdiff_t shift,
rptr = ret->base_addr;
sptr = array->base_addr;
- shift = len == 0 ? 0 : shift % (ptrdiff_t)len;
- if (shift < 0)
- shift += len;
+ /* Avoid the costly modulo for trivially in-bound shifts. */
+ if (shift < 0 || shift >= len)
+ {
+ shift = len == 0 ? 0 : shift % (ptrdiff_t)len;
+ if (shift < 0)
+ shift += len;
+ }
while (rptr)
{
OpenPOWER on IntegriCloud