[llvm] [InstCombine] Fold `select (a == b | other_cond), a, b` to `select (other_cond), a, b` (PR #76203)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 22 11:41:09 PST 2023
================
@@ -965,3 +965,116 @@ define i1 @or_and3_wrong_operand(i1 %a, i1 %b, i32 %x, i32 %y, i1 %d) {
%r = select i1 %cond, i1 %d, i1 %b
ret i1 %r
}
+
+define i32 @or_eq_a_b(i1 %other_cond, i32 %a, i32 %b) {
+; CHECK-LABEL: @or_eq_a_b(
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[OTHER_COND:%.*]], i32 [[A:%.*]], i32 [[B:%.*]]
+; CHECK-NEXT: ret i32 [[SELECT]]
+;
+ %cmp = icmp eq i32 %a, %b
+ %cond = or i1 %other_cond, %cmp
+ %select = select i1 %cond, i32 %a, i32 %b
+ ret i32 %select
+}
+
+define i32 @and_ne_a_b(i1 %other_cond, i32 %a, i32 %b) {
+; CHECK-LABEL: @and_ne_a_b(
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[OTHER_COND:%.*]], i32 [[A:%.*]], i32 [[B:%.*]]
+; CHECK-NEXT: ret i32 [[SELECT]]
+;
+ %cmp = icmp eq i32 %a, %b
+ %cond = or i1 %other_cond, %cmp
+ %select = select i1 %cond, i32 %a, i32 %b
+ ret i32 %select
+}
+
+define i32 @or_eq_a_b_mutated(i1 %other_cond, i32 %a, i32 %b) {
----------------
nikic wrote:
```suggestion
define i32 @or_eq_a_b_commuted(i1 %other_cond, i32 %a, i32 %b) {
```
https://github.com/llvm/llvm-project/pull/76203
More information about the llvm-commits
mailing list