Issue 235683
Summary [InstCombine] ((x + C) & M) - C not folded to x & M when the add has other uses
Labels llvm:instcombine, missed-optimization
Assignees
Reporter chfast
    ```llvm
declare void @use(i64)

define i64 @f(i64 %x) {
  %a = add i64 %x, -8
  call void @use(i64 %a)
  %m = and i64 %a, -8
  %r = add i64 %m, 8
  ret i64 %r
}
```

`%r` is `and i64 %x, -8`: https://alive2.llvm.org/ce/z/AXCzyH

Without the other use of `%a` this folds (`canonicalizeLogicFirst()` makes `%m` into `(x & -8) + -8` and the adds cancel), but that needs a one-use add.

Found in evmone's Keccak: the loop vectorizer's runtime check bound is `((size - 8) & -8) + 8`, with `size - 8` shared with the trip count.

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

Reply via email to