Issue |
131403
|
Summary |
[Clang] Incorrect optimization with unreachable in bitshift of vectors
|
Labels |
clang
|
Assignees |
|
Reporter |
BreadTom
|
Clang x86 20.1.2 incorrectly assumes that (ret_vector0[n] > 1) on line 59 might be true, thus clearing the whole function while GCC 14.2 generates same code without unreachable().
https://godbolt.org/z/sK4GWYbGW
```
#include <stdbool.h>
#include <stddef.h>
#include <inttypes.h>
#include <string.h>
typedef uint8_t expozig_vector_u8_64 __attribute__ ((vector_size (64)));
uint64_t expozig_tokenizer_v2_ret_bitstring(unsigned char * restrict ptr, const uint8_t is_what){
uint64_t ret_val = 0;
expozig_vector_u8_64 input_vector0 = {};
expozig_vector_u8_64 ret_vector0 = {};
memcpy(&input_vector0, ptr, 64);
switch(is_what){
case 0:
ret_vector0 = ((input_vector0 == '_') | ((input_vector0 >= 'a') & (input_vector0 <= 'z')) | ((input_vector0 >= 'A') & (input_vector0 <= 'Z')) | ((input_vector0 >= '0') & (input_vector0 <= '9'))) >> 7;
break;
case 1:
ret_vector0 = ((input_vector0 == 33) | (input_vector0 == 34) | ((input_vector0 >= 37) & (input_vector0 <= 47)) | ((input_vector0 >= 58) & (input_vector0 <= 64)) | ((input_vector0 >= 91) & (input_vector0 <= 94)) | ((input_vector0 >= 123) & (input_vector0 <= 126))) >> 7;
break;
case 2:
ret_vector0 = (input_vector0 == '\n') >> 7;
break;
default:
__builtin_unreachable();
break;
}
/*
case 1:
case '"':
case '\'':
case '@':
case '=':
case '!':
case '|':
case '(':
case ')':
case '[':
case ']':
case ';':
case ',':
case '?':
case ':':
case '%':
case '*':
case '+':
case '<':
case '>':
case '^':
case '\\':
case '{':
case '}':
case '~':
case '.':
case '-':
case '/':
case '&':
*/
for(size_t n = 0; n < 64; ++n){
// Clang "error"
if(ret_vector0[n] > 1)
__builtin_unreachable();
ret_val |= (uint64_t)((uint64_t)ret_vector0[n] << n);
}
return ret_val;
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs