; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine-unsafe-select-transform=0 -instcombine -S | FileCheck %s
-; TODO: All of these should be optimized to a single instruction of select/
-; and/or.
+; TODO: All of these should be optimized to less than or equal to a single
+; instruction of select/and/or.
-; 1. --- X /\ (X /\ Y) ---
+; --- (A op B) op' A / (B op A) op' A ---
-define i1 @merge_logical_and_and(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_logical_and_and(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false
+; (A land B) land A
+define i1 @land_land_left1(i1 %A, i1 %B) {
+; CHECK-LABEL: @land_land_left1(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %X, i1 %Y, i1 false
- %res = and i1 %X, %c
+ %c = select i1 %A, i1 %B, i1 false
+ %res = select i1 %c, i1 %A, i1 false
ret i1 %res
}
-
-define i1 @merge_two_logical_ands(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_two_logical_ands(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false
+define i1 @land_land_left2(i1 %A, i1 %B) {
+; CHECK-LABEL: @land_land_left2(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[C]], i1 [[A]], i1 false
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %X, i1 %Y, i1 false
- %res = select i1 %X, i1 %c, i1 false
+ %c = select i1 %B, i1 %A, i1 false
+ %res = select i1 %c, i1 %A, i1 false
+ ret i1 %res
+}
+
+; (A land B) band A
+define i1 @land_band_left1(i1 %A, i1 %B) {
+; CHECK-LABEL: @land_band_left1(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
+; CHECK-NEXT: ret i1 [[C]]
+;
+ %c = select i1 %A, i1 %B, i1 false
+ %res = and i1 %c, %A
+ ret i1 %res
+}
+define i1 @land_band_left2(i1 %A, i1 %B) {
+; CHECK-LABEL: @land_band_left2(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false
+; CHECK-NEXT: ret i1 [[C]]
+;
+ %c = select i1 %B, i1 %A, i1 false
+ %res = and i1 %c, %A
ret i1 %res
}
-define i1 @merge_and_logical_and(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_and_logical_and(
-; CHECK-NEXT: [[C:%.*]] = and i1 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[X]], i1 [[C]], i1 false
+; (A land B) lor A
+define i1 @land_lor_left1(i1 %A, i1 %B) {
+; CHECK-LABEL: @land_lor_left1(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
+; CHECK-NEXT: [[RES:%.*]] = or i1 [[C]], [[A]]
+; CHECK-NEXT: ret i1 [[RES]]
+;
+ %c = select i1 %A, i1 %B, i1 false
+ %res = select i1 %c, i1 true, i1 %A
+ ret i1 %res
+}
+define i1 @land_lor_left2(i1 %A, i1 %B) {
+; CHECK-LABEL: @land_lor_left2(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[C]], i1 true, i1 [[A]]
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = and i1 %X, %Y
- %res = select i1 %X, i1 %c, i1 false
+ %c = select i1 %B, i1 %A, i1 false
+ %res = select i1 %c, i1 true, i1 %A
ret i1 %res
}
-; 2. --- X /\ (Y /\ X) ---
+; (A land B) bor A
+define i1 @land_bor_left1(i1 %A, i1 %B) {
+; CHECK-LABEL: @land_bor_left1(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
+; CHECK-NEXT: [[RES:%.*]] = or i1 [[C]], [[A]]
+; CHECK-NEXT: ret i1 [[RES]]
+;
+ %c = select i1 %A, i1 %B, i1 false
+ %res = or i1 %c, %A
+ ret i1 %res
+}
+define i1 @land_bor_left2(i1 %A, i1 %B) {
+; CHECK-LABEL: @land_bor_left2(
+; CHECK-NEXT: ret i1 [[A:%.*]]
+;
+ %c = select i1 %B, i1 %A, i1 false
+ %res = or i1 %c, %A
+ ret i1 %res
+}
-; This can be optimized to 'and i1 %X, %Y'
-define i1 @merge_logical_and_and2(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_logical_and_and2(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[Y:%.*]], i1 [[X:%.*]], i1 false
+; (A band B) land A
+define i1 @band_land_left1(i1 %A, i1 %B) {
+; CHECK-LABEL: @band_land_left1(
+; CHECK-NEXT: [[C:%.*]] = and i1 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %Y, i1 %X, i1 false
- %res = and i1 %X, %c
+ %c = and i1 %A, %B
+ %res = select i1 %c, i1 %A, i1 false
+ ret i1 %res
+}
+define i1 @band_land_left2(i1 %A, i1 %B) {
+; CHECK-LABEL: @band_land_left2(
+; CHECK-NEXT: [[C:%.*]] = and i1 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT: ret i1 [[C]]
+;
+ %c = and i1 %B, %A
+ %res = select i1 %c, i1 %A, i1 false
ret i1 %res
}
-define i1 @merge_two_logical_ands2(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_two_logical_ands2(
-; CHECK-NEXT: [[TMP1:%.*]] = and i1 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT: ret i1 [[TMP1]]
+; (A band B) lor A
+define i1 @band_lor_left1(i1 %A, i1 %B) {
+; CHECK-LABEL: @band_lor_left1(
+; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %Y, i1 %X, i1 false
- %res = select i1 %X, i1 %c, i1 false
+ %c = and i1 %A, %B
+ %res = select i1 %c, i1 true, i1 %A
+ ret i1 %res
+}
+define i1 @band_lor_left2(i1 %A, i1 %B) {
+; CHECK-LABEL: @band_lor_left2(
+; CHECK-NEXT: ret i1 [[A:%.*]]
+;
+ %c = and i1 %B, %A
+ %res = select i1 %c, i1 true, i1 %A
ret i1 %res
}
-define i1 @merge_and_logical_and2(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_and_logical_and2(
-; CHECK-NEXT: [[C:%.*]] = and i1 [[Y:%.*]], [[X:%.*]]
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[X]], i1 [[C]], i1 false
+; (A lor B) land A
+define i1 @lor_land_left1(i1 %A, i1 %B) {
+; CHECK-LABEL: @lor_land_left1(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = and i1 [[C]], [[A]]
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = and i1 %Y, %X
- %res = select i1 %X, i1 %c, i1 false
+ %c = select i1 %A, i1 true, i1 %B
+ %res = select i1 %c, i1 %A, i1 false
+ ret i1 %res
+}
+define i1 @lor_land_left2(i1 %A, i1 %B) {
+; CHECK-LABEL: @lor_land_left2(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[C]], i1 [[A]], i1 false
+; CHECK-NEXT: ret i1 [[RES]]
+;
+ %c = select i1 %B, i1 true, i1 %A
+ %res = select i1 %c, i1 %A, i1 false
ret i1 %res
}
-; 3. --- (X /\ Y) /\ X ---
+; (A lor B) band A
+define i1 @lor_band_left1(i1 %A, i1 %B) {
+; CHECK-LABEL: @lor_band_left1(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = and i1 [[C]], [[A]]
+; CHECK-NEXT: ret i1 [[RES]]
+;
+ %c = select i1 %A, i1 true, i1 %B
+ %res = and i1 %c, %A
+ ret i1 %res
+}
+define i1 @lor_band_left2(i1 %A, i1 %B) {
+; CHECK-LABEL: @lor_band_left2(
+; CHECK-NEXT: ret i1 [[A:%.*]]
+;
+ %c = select i1 %B, i1 true, i1 %A
+ %res = and i1 %c, %A
+ ret i1 %res
+}
-define i1 @merge_logical_and_and3(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_logical_and_and3(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false
+; (A lor B) lor A
+define i1 @lor_lor_left1(i1 %A, i1 %B) {
+; CHECK-LABEL: @lor_lor_left1(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %X, i1 %Y, i1 false
- %res = and i1 %c, %X
+ %c = select i1 %A, i1 true, i1 %B
+ %res = select i1 %c, i1 true, i1 %A
+ ret i1 %res
+}
+define i1 @lor_lor_left2(i1 %A, i1 %B) {
+; CHECK-LABEL: @lor_lor_left2(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[C]], i1 true, i1 [[A]]
+; CHECK-NEXT: ret i1 [[RES]]
+;
+ %c = select i1 %B, i1 true, i1 %A
+ %res = select i1 %c, i1 true, i1 %A
ret i1 %res
}
-define i1 @merge_two_logical_ands3(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_two_logical_ands3(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false
+; (A lor B) bor A
+define i1 @lor_bor_left1(i1 %A, i1 %B) {
+; CHECK-LABEL: @lor_bor_left1(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %X, i1 %Y, i1 false
- %res = select i1 %c, i1 %X, i1 false
+ %c = select i1 %A, i1 true, i1 %B
+ %res = or i1 %c, %A
ret i1 %res
}
-
-; This can be optimized to 'and i1 %X, %Y'
-define i1 @merge_and_logical_and3(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_and_logical_and3(
-; CHECK-NEXT: [[C:%.*]] = and i1 [[X:%.*]], [[Y:%.*]]
+define i1 @lor_bor_left2(i1 %A, i1 %B) {
+; CHECK-LABEL: @lor_bor_left2(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = and i1 %X, %Y
- %res = select i1 %c, i1 %X, i1 false
+ %c = select i1 %B, i1 true, i1 %A
+ %res = or i1 %c, %A
ret i1 %res
}
-; 4. --- (Y /\ X) /\ X ---
+; (A bor B) land A
+define i1 @bor_land_left1(i1 %A, i1 %B) {
+; CHECK-LABEL: @bor_land_left1(
+; CHECK-NEXT: ret i1 [[A:%.*]]
+;
+ %c = or i1 %A, %B
+ %res = select i1 %c, i1 %A, i1 false
+ ret i1 %res
+}
+define i1 @bor_land_left2(i1 %A, i1 %B) {
+; CHECK-LABEL: @bor_land_left2(
+; CHECK-NEXT: ret i1 [[A:%.*]]
+;
+ %c = or i1 %B, %A
+ %res = select i1 %c, i1 %A, i1 false
+ ret i1 %res
+}
-; This can be optimized to 'and i1 %X, %Y'
-define i1 @merge_logical_and_and4(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_logical_and_and4(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[Y:%.*]], i1 [[X:%.*]], i1 false
+; (A bor B) lor A
+define i1 @bor_lor_left1(i1 %A, i1 %B) {
+; CHECK-LABEL: @bor_lor_left1(
+; CHECK-NEXT: [[C:%.*]] = or i1 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: ret i1 [[C]]
+;
+ %c = or i1 %A, %B
+ %res = select i1 %c, i1 true, i1 %A
+ ret i1 %res
+}
+define i1 @bor_lor_left2(i1 %A, i1 %B) {
+; CHECK-LABEL: @bor_lor_left2(
+; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], [[A:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %Y, i1 %X, i1 false
- %res = and i1 %c, %X
+ %c = or i1 %B, %A
+ %res = select i1 %c, i1 true, i1 %A
ret i1 %res
}
-define i1 @merge_two_logical_ands4(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_two_logical_ands4(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[Y:%.*]], i1 [[X:%.*]], i1 false
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[C]], i1 [[X]], i1 false
+; --- A op (A op' B) / A op (B op' A) ---
+
+; A land (A land B)
+define i1 @land_land_right1(i1 %A, i1 %B) {
+; CHECK-LABEL: @land_land_right1(
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %Y, i1 %X, i1 false
- %res = select i1 %c, i1 %X, i1 false
+ %c = select i1 %A, i1 %B, i1 false
+ %res = select i1 %A, i1 %c, i1 false
+ ret i1 %res
+}
+define i1 @land_land_right2(i1 %A, i1 %B) {
+; CHECK-LABEL: @land_land_right2(
+; CHECK-NEXT: [[TMP1:%.*]] = and i1 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: ret i1 [[TMP1]]
+;
+ %c = select i1 %B, i1 %A, i1 false
+ %res = select i1 %A, i1 %c, i1 false
ret i1 %res
}
-; This can be optimized to 'and i1 %X, %Y'
-define i1 @merge_and_logical_and4(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_and_logical_and4(
-; CHECK-NEXT: [[C:%.*]] = and i1 [[Y:%.*]], [[X:%.*]]
+; A band (A land B)
+define i1 @land_band_right1(i1 %A, i1 %B) {
+; CHECK-LABEL: @land_band_right1(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
; CHECK-NEXT: ret i1 [[C]]
;
- %c = and i1 %Y, %X
- %res = select i1 %c, i1 %X, i1 false
+ %c = select i1 %A, i1 %B, i1 false
+ %res = and i1 %A, %c
ret i1 %res
}
-
-
-; 5. --- X \/ (X \/ Y) ---
-
-define i1 @merge_logical_or_or(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_logical_or_or(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
+define i1 @land_band_right2(i1 %A, i1 %B) {
+; CHECK-LABEL: @land_band_right2(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %X, i1 true, i1 %Y
- %res = or i1 %X, %c
+ %c = select i1 %B, i1 %A, i1 false
+ %res = and i1 %A, %c
ret i1 %res
}
-define i1 @merge_two_logical_ors(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_two_logical_ors(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
+; A lor (A land B)
+define i1 @land_lor_right1(i1 %A, i1 %B) {
+; CHECK-LABEL: @land_lor_right1(
+; CHECK-NEXT: ret i1 [[A:%.*]]
+;
+ %c = select i1 %A, i1 %B, i1 false
+ %res = select i1 %A, i1 true, i1 %c
+ ret i1 %res
+}
+define i1 @land_lor_right2(i1 %A, i1 %B) {
+; CHECK-LABEL: @land_lor_right2(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 true, i1 [[C]]
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %X, i1 true, i1 %Y
- %res = select i1 %X, i1 true, i1 %c
+ %c = select i1 %B, i1 %A, i1 false
+ %res = select i1 %A, i1 true, i1 %c
ret i1 %res
}
-define i1 @merge_or_logical_or(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_or_logical_or(
-; CHECK-NEXT: [[C:%.*]] = or i1 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[X]], i1 true, i1 [[C]]
+; A bor (A land B)
+define i1 @land_bor_right1(i1 %A, i1 %B) {
+; CHECK-LABEL: @land_bor_right1(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
+; CHECK-NEXT: [[RES:%.*]] = or i1 [[C]], [[A]]
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = or i1 %X, %Y
- %res = select i1 %X, i1 true, i1 %c
+ %c = select i1 %A, i1 %B, i1 false
+ %res = or i1 %A, %c
ret i1 %res
}
-
-; 6. --- X \/ (Y \/ X) ---
-
-; This can be optimized to 'or i1 %X, %Y'
-define i1 @merge_logical_or_or2(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_logical_or_or2(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[Y:%.*]], i1 true, i1 [[X:%.*]]
-; CHECK-NEXT: ret i1 [[C]]
+define i1 @land_bor_right2(i1 %A, i1 %B) {
+; CHECK-LABEL: @land_bor_right2(
+; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %Y, i1 true, i1 %X
- %res = or i1 %X, %c
+ %c = select i1 %B, i1 %A, i1 false
+ %res = or i1 %A, %c
ret i1 %res
}
-define i1 @merge_two_logical_ors2(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_two_logical_ors2(
-; CHECK-NEXT: [[TMP1:%.*]] = or i1 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT: ret i1 [[TMP1]]
+; A land (A band B)
+define i1 @band_land_right1(i1 %A, i1 %B) {
+; CHECK-LABEL: @band_land_right1(
+; CHECK-NEXT: [[C:%.*]] = and i1 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[C]], i1 false
+; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %Y, i1 true, i1 %X
- %res = select i1 %X, i1 true, i1 %c
+ %c = and i1 %A, %B
+ %res = select i1 %A, i1 %c, i1 false
+ ret i1 %res
+}
+define i1 @band_land_right2(i1 %A, i1 %B) {
+; CHECK-LABEL: @band_land_right2(
+; CHECK-NEXT: [[C:%.*]] = and i1 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[C]], i1 false
+; CHECK-NEXT: ret i1 [[RES]]
+;
+ %c = and i1 %B, %A
+ %res = select i1 %A, i1 %c, i1 false
ret i1 %res
}
-define i1 @merge_or_logical_or2(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_or_logical_or2(
-; CHECK-NEXT: [[C:%.*]] = or i1 [[Y:%.*]], [[X:%.*]]
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[X]], i1 true, i1 [[C]]
+; A lor (A band B)
+define i1 @band_lor_right1(i1 %A, i1 %B) {
+; CHECK-LABEL: @band_lor_right1(
+; CHECK-NEXT: [[C:%.*]] = and i1 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 true, i1 [[C]]
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = or i1 %Y, %X
- %res = select i1 %X, i1 true, i1 %c
+ %c = and i1 %A, %B
+ %res = select i1 %A, i1 true, i1 %c
+ ret i1 %res
+}
+define i1 @band_lor_right2(i1 %A, i1 %B) {
+; CHECK-LABEL: @band_lor_right2(
+; CHECK-NEXT: [[C:%.*]] = and i1 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 true, i1 [[C]]
+; CHECK-NEXT: ret i1 [[RES]]
+;
+ %c = and i1 %B, %A
+ %res = select i1 %A, i1 true, i1 %c
ret i1 %res
}
-; 7. --- (X \/ Y) \/ X ---
+; A land (A lor B)
+define i1 @lor_land_right1(i1 %A, i1 %B) {
+; CHECK-LABEL: @lor_land_right1(
+; CHECK-NEXT: ret i1 [[A:%.*]]
+;
+ %c = select i1 %A, i1 true, i1 %B
+ %res = select i1 %A, i1 %c, i1 false
+ ret i1 %res
+}
+define i1 @lor_land_right2(i1 %A, i1 %B) {
+; CHECK-LABEL: @lor_land_right2(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[C]], i1 false
+; CHECK-NEXT: ret i1 [[RES]]
+;
+ %c = select i1 %B, i1 true, i1 %A
+ %res = select i1 %A, i1 %c, i1 false
+ ret i1 %res
+}
-define i1 @merge_logical_or_or3(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_logical_or_or3(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
-; CHECK-NEXT: ret i1 [[C]]
+; A band (A lor B)
+define i1 @lor_band_right1(i1 %A, i1 %B) {
+; CHECK-LABEL: @lor_band_right1(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = and i1 [[C]], [[A]]
+; CHECK-NEXT: ret i1 [[RES]]
+;
+ %c = select i1 %A, i1 true, i1 %B
+ %res = and i1 %A, %c
+ ret i1 %res
+}
+define i1 @lor_band_right2(i1 %A, i1 %B) {
+; CHECK-LABEL: @lor_band_right2(
+; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %X, i1 true, i1 %Y
- %res = or i1 %c, %X
+ %c = select i1 %B, i1 true, i1 %A
+ %res = and i1 %A, %c
ret i1 %res
}
-define i1 @merge_two_logical_ors3(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_two_logical_ors3(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
-; CHECK-NEXT: ret i1 [[C]]
+; A lor (A lor B)
+define i1 @lor_lor_right1(i1 %A, i1 %B) {
+; CHECK-LABEL: @lor_lor_right1(
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %X, i1 true, i1 %Y
- %res = select i1 %c, i1 true, i1 %X
+ %c = select i1 %A, i1 true, i1 %B
+ %res = select i1 %A, i1 true, i1 %c
+ ret i1 %res
+}
+define i1 @lor_lor_right2(i1 %A, i1 %B) {
+; CHECK-LABEL: @lor_lor_right2(
+; CHECK-NEXT: [[TMP1:%.*]] = or i1 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: ret i1 [[TMP1]]
+;
+ %c = select i1 %B, i1 true, i1 %A
+ %res = select i1 %A, i1 true, i1 %c
ret i1 %res
}
-; This can be optimized to 'or i1 %Y, %X'
-define i1 @merge_or_logical_or3(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_or_logical_or3(
-; CHECK-NEXT: [[C:%.*]] = or i1 [[X:%.*]], [[Y:%.*]]
+; A bor (A lor B)
+define i1 @lor_bor_right1(i1 %A, i1 %B) {
+; CHECK-LABEL: @lor_bor_right1(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = or i1 %X, %Y
- %res = select i1 %c, i1 true, i1 %X
+ %c = select i1 %A, i1 true, i1 %B
+ %res = or i1 %A, %c
ret i1 %res
}
-
-; 8. --- (Y \/ X) \/ X ---
-
-; This can be optimized to 'or i1 %Y, %X'
-define i1 @merge_logical_or_or4(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_logical_or_or4(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[Y:%.*]], i1 true, i1 [[X:%.*]]
+define i1 @lor_bor_right2(i1 %A, i1 %B) {
+; CHECK-LABEL: @lor_bor_right2(
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %Y, i1 true, i1 %X
- %res = or i1 %c, %X
+ %c = select i1 %B, i1 true, i1 %A
+ %res = or i1 %A, %c
ret i1 %res
}
-define i1 @merge_two_logical_ors4(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_two_logical_ors4(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[Y:%.*]], i1 true, i1 [[X:%.*]]
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[C]], i1 true, i1 [[X]]
+; A land (A bor B)
+define i1 @bor_land_right1(i1 %A, i1 %B) {
+; CHECK-LABEL: @bor_land_right1(
+; CHECK-NEXT: [[C:%.*]] = or i1 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[C]], i1 false
+; CHECK-NEXT: ret i1 [[RES]]
+;
+ %c = or i1 %A, %B
+ %res = select i1 %A, i1 %c, i1 false
+ ret i1 %res
+}
+define i1 @bor_land_right2(i1 %A, i1 %B) {
+; CHECK-LABEL: @bor_land_right2(
+; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[C]], i1 false
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %Y, i1 true, i1 %X
- %res = select i1 %c, i1 true, i1 %X
+ %c = or i1 %B, %A
+ %res = select i1 %A, i1 %c, i1 false
ret i1 %res
}
-; This can be optimized to 'or i1 %Y, %X'
-define i1 @merge_or_logical_or4(i1 %X, i1 %Y) {
-; CHECK-LABEL: @merge_or_logical_or4(
-; CHECK-NEXT: [[C:%.*]] = or i1 [[Y:%.*]], [[X:%.*]]
-; CHECK-NEXT: ret i1 [[C]]
+; A lor (A bor B)
+define i1 @bor_lor_right1(i1 %A, i1 %B) {
+; CHECK-LABEL: @bor_lor_right1(
+; CHECK-NEXT: [[C:%.*]] = or i1 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 true, i1 [[C]]
+; CHECK-NEXT: ret i1 [[RES]]
+;
+ %c = or i1 %A, %B
+ %res = select i1 %A, i1 true, i1 %c
+ ret i1 %res
+}
+define i1 @bor_lor_right2(i1 %A, i1 %B) {
+; CHECK-LABEL: @bor_lor_right2(
+; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 true, i1 [[C]]
+; CHECK-NEXT: ret i1 [[RES]]
;
- %c = or i1 %Y, %X
- %res = select i1 %c, i1 true, i1 %X
+ %c = or i1 %B, %A
+ %res = select i1 %A, i1 true, i1 %c
ret i1 %res
}