[PATCH] D114666: [InstSimplify] Fold bool(X) ^ 1 == 0 to X
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 28 07:46:23 PST 2021
spatel added inline comments.
================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:2692
// A boolean compared to true/false can be simplified in 14 out of the 20
+
----------------
The comment and code structure suggest that we are missing related patterns.
Can we generalize this to look through a 'not' of LHS and invert/swap the predicate?
For example, we should be able to reduce these patterns too:
```
define i1 @not_cmp_ne(i1 %x) {
%not = xor i1 %x, true
%cmp = icmp ne i1 %not, true
ret i1 %cmp
}
define i1 @not_cmp_ult(i1 %x) {
%not = xor i1 %x, true
%cmp = icmp ult i1 %not, 1
ret i1 %cmp
}
```
================
Comment at: llvm/test/Transforms/InstSimplify/icmp.ll:194
+ %not = xor i1 %x, true
+ %t0 = sext i1 %not to i32
+ %cmp = icmp eq i32 %t0, 0
----------------
We want tests with the sext instruction because this code handles looking through that cast (and possible others?), but the minimal pattern does not include casts. So we need to add tests for code with no sext ops.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114666/new/
https://reviews.llvm.org/D114666
More information about the llvm-commits
mailing list