Issue 96519
Summary Failure to determine condition is always false using known bits
Labels missed-optimization
Assignees
Reporter Kmeakin
    ASCII letters can be converted to lowercase by or-ing with `0x20`. Therefore the 3rd `if` in `src` is impossible and should be deleted:

[godbolt](https://godbolt.org/z/WeKbxEao3)
[alive](https://alive2.llvm.org/ce/z/NSVJ7q)
```c
#include <stdint.h>

typedef uint32_t u8;
typedef uint32_t u32;

u32 src(u8 b) {
    if (b >= '0' && b <= '9') {
        return b - '0';
 }

    b |= 0x20;

    if (b >= 'a' && b <= 'f') {
 return b - 'a' + 10;
    }

    if (b >= 'A' && b <= 'F') {
 return b - 'A' + 10;
    }

    return -1;
}

u32 tgt(u8 b) {
    if (b >= '0' && b <= '9') {
        return b - '0';
 }

    b |= 0x20;

    if (b >= 'a' && b <= 'f') {
 return b - 'a' + 10;
    }

    return -1;
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to