Issue 98946
Summary function return `range` metadata not inferred from `assume`s
Labels missed-optimization
Assignees
Reporter Kmeakin
    The propagation of range information from `assume` is very fragile. 
Things that prevent it from propagating:

- The `assume` is in its own function
- The condition passed to `assume` is extracted into a helper function (eg `is_surrogate`)
- The condition passed to `assume` combines two comparisons with `or`
- The condition passed to `assume` is the negation of another comparison

https://godbolt.org/z/hvdxE1xKn
```c
#include <stdbool.h>
#include <stdint.h>

typedef uint32_t u32;

void assume(bool b) { __builtin_assume(b); }

bool is_surrogate(u32 c) { return 0xD800 <= c && c <= 0xDFFF; }

// range not inferred
u32 f1(u32 c) {
    assume(!is_surrogate(c));
    return c;
}

// range not inferred
u32 f2(u32 c) {
 __builtin_assume(!is_surrogate(c));
    return c;
}

// range not inferred
u32 f3(u32 c) {
    __builtin_assume(!(0xD800 <= c && c <= 0xDFFF));
    return c;
}

// range not inferred
u32 f4(u32 c) {
    __builtin_assume(c < 0xD800 || c > 0xDFFF);
    return c;
}

// range(i32 0, 55296) inferred
u32 f5(u32 c) {
 __builtin_assume(c < 0xD800);
    return c;
}

// range(i32 55297, 0) inferred
u32 f6(u32 c) {
    __builtin_assume(c > 0xD800);
    return c;
}

// range not inferred
u32 f7(u32 c) {
    __builtin_assume(!(0xD800 <= c));
    return c;
}

// range not inferred
u32 f8(u32 c) {
    __builtin_assume(!(c <= 0xDFFF));
    return c;
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to