Skip to content

WRONG code when enabling Loop Vectorizer with -Os #82665

Closed
@JonPsson1

Description

@JonPsson1

This program should print 1:

cat wrong0.i

int printf(const char *, ...);
int *IntPtr = 0;
int Val, ValB;
int *IntPtrArr5[5] = {0, 0, 0, 0, 0};
int *IntPtr2 = &ValB;
int main() {
  for (int IV1 = 0; IV1 < 5; IV1++)
    IntPtrArr5[IV1] = &Val;
  for (int IV2 = 1; IV2 <= 4; IV2 += 1) {
    int **PtrPtr = &IntPtr2;    // -> IntPtr2          
    int **PtrPtr2 = &IntPtr;    // -> IntPtr
    *PtrPtr2 = IntPtrArr5[IV2]; // -> IntPtr -> Val  
    *IntPtr2 ^= 1;              //    ValB = 1         Val = 1 (2nd iter)
    *PtrPtr = IntPtrArr5[IV2];  // -> IntPtr2 -> Val
  }
  printf("checksum = %X\n", Val);
}

In the first iteration, IntPtr2 points to ValB and sets it to 1. Then, only in the second iteration does IntPtr2 point to Val and set that to 1. I wonder if the loopvectorizer has done something wrong, or if there is some later pass possibly that is messing it up..?

rm a.out; clang -O0 -march=z16 wrong0.i -o a.out -w; ./a.out
checksum = 1

rm a.out; clang -Os -march=z16 wrong0.i -o a.out -w -fno-vectorize -fno-slp-vectorize; ./a.out
checksum = 1

rm a.out; clang -Os -march=z16 wrong0.i -o a.out -w -fno-slp-vectorize; ./a.out
checksum = 0

@fhahn @david-arm @nilanjana87

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions