https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115636
Bug ID: 115636 Summary: Missing optimzation: fold ` (w << (unsigned int)((flag ? a : b) - 32768))` to ` flag ? w << (unsigned int)(a - 32768) : 0 ` Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: zhiwuyazhe154 at gmail dot com Target Milestone: --- godbolt example: https://godbolt.org/z/W5hr6G8oK code example: ```cpp short b, n; void func(signed char w, signed char flag, unsigned long long int a) { n = 0 >= (w << (unsigned int)((flag ? a : b) - 32768)); } ``` In this case, when flag != 0, no matter what the value of b is, the value of (unsigned int)(b - 32768) is much greater than 8, which means that w will be shifted left more than 8 times. According to the behavior of gcc, the value of w will be assigned to 0, that is, as long as flag != 0, then w will be 0, regardless of the value of b.