[llvm] [InstCombine] Improve select equiv fold for plain condition (PR #83405)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 8 04:47:43 PDT 2024
================
@@ -3759,3 +3759,18 @@ define i32 @sequence_select_with_same_cond_extra_use(i1 %c1, i1 %c2){
%s3 = select i1 %c1, i32 789, i32 %s2
ret i32 %s3
}
+
+define i8 @sequence_select_with_same_cond_multi_arms(i1 %cond0, i1 %cond1, i8 %a, i8 %b) {
+; CHECK-LABEL: @sequence_select_with_same_cond_multi_arms(
+; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[TMP1:%.*]], i8 [[A:%.*]], i8 [[B:%.*]]
+; CHECK-NEXT: [[SEL1_NEW:%.*]] = select i1 [[COND1:%.*]], i8 [[A]], i8 2
+; CHECK-NEXT: [[SEL4:%.*]] = select i1 [[COND1]], i8 [[SEL2]], i8 3
+; CHECK-NEXT: [[SEL3:%.*]] = select i1 [[TMP1]], i8 [[SEL1_NEW]], i8 [[SEL4]]
+; CHECK-NEXT: ret i8 [[SEL3]]
+;
+ %sel0 = select i1 %cond0, i8 %a, i8 %b
----------------
vfdff wrote:
* this case has 2 transformation in combine, https://alive2.llvm.org/ce/z/ChFi5F
- first
```
define i8 @fist(i1 %cond0, i1 %cond1, i8 %a, i8 %b) {
%sel0 = select i1 %cond0, i8 %a, i8 %b
%sel1 = select i1 %cond1, i8 %sel0, i8 2
%sel2 = select i1 %cond1, i8 %sel0, i8 3 ; update directly base on first 3 nodes
%sel3 = select i1 %cond0, i8 %sel1, i8 %sel2
ret i8 %sel3
}
```
- second
```
define i8 @second(i1 %cond0, i1 %cond1, i8 %a, i8 %b) {
%sel0 = select i1 %cond0, i8 %a, i8 %b
%sel1.new = select i1 %cond1, i8 %a, i8 2
%sel2 = select i1 %cond1, i8 %sel0, i8 3
%sel3 = select i1 %cond0, i8 %sel1.new, i8 %sel2; base on the 4 nodes
ret i8 %sel3
}
```
https://github.com/llvm/llvm-project/pull/83405
More information about the llvm-commits
mailing list