one bit error

This is my first try on mailing list. Please correct if I am wrong.

On compiling this program using clang 3.9.1

#include <stdio.h>
#include <stdlib.h>

int main () {
int i,j;
static int x[4000][4000];
for (j = 0; j < 4000; j++) {
for (i = 0; i < 4000; i++) {
x[j][i] = i + j; }

got compiled to

mov dword ptr [rbp - 4], 0
mov dword ptr [rbp - 12], 0
.LBB0_1: # =>This Loop Header: Depth=1
cmp dword ptr [rbp - 12], 4000
jge .LBB0_8
mov dword ptr [rbp - 8], 0
.LBB0_3: # Parent Loop BB0_1 Depth=1
cmp dword ptr [rbp - 8], 4000

while gcc 7 gives this

mov DWORD PTR [rbp-8], 0
cmp DWORD PTR [rbp-8], 3999
jg .L2
mov DWORD PTR [rbp-4], 0
cmp DWORD PTR [rbp-4], 3999
jg .L3

I think it should be 3999.

What makes you think there is an issue? Do you observe an actual issue when you run your program?
(Did you notice that clang uses jge while gcc uses jg?)

If you take a look at the generated code, you will see that clang uses
         cmp dword ptr [rbp - 12], 4000
         jge .LBB0_8
which is equal (in C) to
   if (i >= 4000)

while gcc generates
         cmp DWORD PTR [rbp-8], 3999
         jg .L2
which is equal to
   if (i > 3999)

I don't see any difference here. Why do you think this is an issue?

21.01.2017 07:46, Ashish Gahlot via cfe-dev пишет:

sorry about that, I missed that detail. Thanks for correcting.