Issue 63321
Summary `(-1 + b) & x` → `select b, 0, x` should work for `!range {0, 2}` too, not just for `i1`
Labels new issue
Assignees
Reporter scottmcm
    Original rust demonstration: <https://rust.godbolt.org/z/Y7n96orba>

LLVM today will simplify <https://llvm.godbolt.org/z/4jbjorjoe>
```llvm
  %rhs = zext i1 %first_take to i64
  %mask = add i64 -1, %rhs
  %0 = and i64 %step, %mask
```
to
```llvm
  %0 = select i1 %first_take, i64 0, i64 %step
```

However, if that `i1` instead comes from a `load i8` with `{0, 2}` range metadata, it no longer can: <https://llvm.godbolt.org/z/jevoe764x>
```llvm
  %0 = load i8, ptr %first_take, align 1, !range !1, !noundef !2
  %_5 = trunc i8 %0 to i1
  %rhs = zext i1 %_5 to i64
  %mask = add i64 -1, %rhs
  %_6 = load i64, ptr %step, align 8
  %1 = and i64 %_6, %mask
```
stays as just
```llvm
  %0 = load i8, ptr %first_take, align 1, !range !0, !noundef !1
  %rhs = zext i8 %0 to i64
  %mask = add nsw i64 %rhs, -1
  %_6 = load i64, ptr %step, align 8
  %1 = and i64 %mask, %_6
```


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to