aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/generated/cshift0_r8.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgfortran/generated/cshift0_r8.c')
-rw-r--r--libgfortran/generated/cshift0_r8.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/libgfortran/generated/cshift0_r8.c b/libgfortran/generated/cshift0_r8.c
index a3f7479..73afb8a 100644
--- a/libgfortran/generated/cshift0_r8.c
+++ b/libgfortran/generated/cshift0_r8.c
@@ -97,9 +97,13 @@ cshift0_r8 (gfc_array_r8 *ret, const gfc_array_r8 *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)
{