<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/98946>98946</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            function return `range` metadata not inferred from `assume`s 
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            missed-optimization
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Kmeakin
      </td>
    </tr>
</table>

<pre>
    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;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8lstu2zoTgJ-G2gxiUEPrttCiiaNNt90blERJ_H-JFMiR4_TpD2g5sZs6QH3aHsCQLXIu31zoofRe90apkiWPLNlFcqHBuvLrpOT_tYlq276W3wYFs7Oz7CVpa8B24KTpFWjTWTeti52zE7CUS--XSbGUg_ZwUO4VOid7PaoNML5j_Mu3QZveAw2SYHbqoAyBplX_3Yvpmfiyyq_PBwgUH-1rA5o82BcD3WKaAHIt3ljT6hPdLL1XLZD9yYQ6kpMNqRa0IQsSBjXOyr3bA4a56oOa9nu_OGd7SUGZYXGXr8ZOtTbKA73Y8DJLp701Hl40DUHUumD1TnwaFBh1KYw0lgblrhxcZ3Egmn3ILFYMq962tR1pY13PsPrOsBoO7fE5Pn59U0r5-mnO7yi0acalVcDEk6e2tnbcDEw8f7KvDV1vn570OqtWdbBoQwL3BItAJh6vRQ5Wt3AOE_PgBGqGBbDsEfb7etEjabO_CIRSiEdg2e7ayknvh6JhvgiE5s2UU7Q4A_y4yzkPxEzsoAGGKcM0_FhX-HFXVdUNB2sWz2fBWArnQTmn2nU7-OriD07XLQC4xMcw_kAZhNeYLuJn2OaSqvth8DbMjZT-d0zi0wTdxmKY_2LB_g7v9h7eE9J7g2VPLHs6YT5fMf5bQIa5Fgic4RMkCRZpALoBnPxy0a9p_wBZgMoCHf-ELL03lc9_AO6zuma_3Yd_qeHy-8F-6yS8_edHbSnaQhQyUmWcYcyzWMRxNJRJ0uRCyqwRDY9FHrdxIgsUqUARd2LbRLpEjluexUlcYJzEG9x2SVanbZNj1uSyYFuuJqnHzTgepjB-Iu39osoiL7ZpNMpajf50IUGcdJh8D3YmPenvpzHHEMNNxZVB-6Fees-2fNSe_MUeaRpV-T7Dz-GylK8NmnKYFMlWkvwh7T_fYjxEixvLD4NT07DUm8ZODKvg8_z1MDv7P9UQw-oUkGdYrTEdSvwnAAD__-uys4Q">