[llvm] 0cb3530 - [ConstraintElim] Add additional switch case and use i8 instead of i32.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 22 03:12:15 PDT 2023
Author: Florian Hahn
Date: 2023-09-22T11:11:46+01:00
New Revision: 0cb353068056690dbe91c69336f7e6917f537b40
URL: https://github.com/llvm/llvm-project/commit/0cb353068056690dbe91c69336f7e6917f537b40
DIFF: https://github.com/llvm/llvm-project/commit/0cb353068056690dbe91c69336f7e6917f537b40.diff
LOG: [ConstraintElim] Add additional switch case and use i8 instead of i32.
Shorten the types used to i8 for cheaper verification and add test case
where 2 cases have the same destination, as suggested in #67061.
Added:
Modified:
llvm/test/Transforms/ConstraintElimination/switch.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/ConstraintElimination/switch.ll b/llvm/test/Transforms/ConstraintElimination/switch.ll
index 25e6d34f0250c45..ad3bc5c048f97fd 100644
--- a/llvm/test/Transforms/ConstraintElimination/switch.ll
+++ b/llvm/test/Transforms/ConstraintElimination/switch.ll
@@ -3,143 +3,188 @@
declare void @may_unwind()
-define i1 @test_switch_in_block_with_assume(i32 %x) {
+define i1 @test_switch_in_block_with_assume(i8 %x) {
; CHECK-LABEL: @test_switch_in_block_with_assume(
; CHECK-NEXT: entry:
; CHECK-NEXT: call void @may_unwind()
-; CHECK-NEXT: [[C_1:%.*]] = icmp ult i32 [[X:%.*]], 10
+; CHECK-NEXT: [[C_1:%.*]] = icmp ult i8 [[X:%.*]], 10
; CHECK-NEXT: call void @llvm.assume(i1 [[C_1]])
-; CHECK-NEXT: switch i32 0, label [[EXIT_1:%.*]] [
-; CHECK-NEXT: i32 1, label [[EXIT_2:%.*]]
+; CHECK-NEXT: switch i8 0, label [[EXIT_1:%.*]] [
+; CHECK-NEXT: i8 1, label [[EXIT_2:%.*]]
; CHECK-NEXT: ]
; CHECK: exit.1:
-; CHECK-NEXT: [[C_2:%.*]] = icmp ult i32 [[X]], 9
+; CHECK-NEXT: [[C_2:%.*]] = icmp ult i8 [[X]], 9
; CHECK-NEXT: [[RES_1:%.*]] = xor i1 true, [[C_2]]
; CHECK-NEXT: ret i1 [[RES_1]]
; CHECK: exit.2:
-; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[X]], 9
+; CHECK-NEXT: [[C_3:%.*]] = icmp ult i8 [[X]], 9
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 true, [[C_3]]
; CHECK-NEXT: ret i1 [[RES_2]]
;
entry:
call void @may_unwind()
- %c.1 = icmp ult i32 %x, 10
+ %c.1 = icmp ult i8 %x, 10
call void @llvm.assume(i1 %c.1)
- switch i32 0, label %exit.1 [
- i32 1, label %exit.2
+ switch i8 0, label %exit.1 [
+ i8 1, label %exit.2
]
exit.1:
- %t.1 = icmp ult i32 %x, 10
- %c.2 = icmp ult i32 %x, 9
+ %t.1 = icmp ult i8 %x, 10
+ %c.2 = icmp ult i8 %x, 9
%res.1 = xor i1 %t.1, %c.2
ret i1 %res.1
exit.2:
- %t.2 = icmp ult i32 %x, 10
- %c.3 = icmp ult i32 %x, 9
+ %t.2 = icmp ult i8 %x, 10
+ %c.3 = icmp ult i8 %x, 9
%res.2 = xor i1 %t.2, %c.3
ret i1 %res.2
}
declare void @llvm.assume(i1)
-define i1 @simplify_based_on_switch(i32 %x) {
+define i1 @simplify_based_on_switch(i8 %x) {
; CHECK-LABEL: @simplify_based_on_switch(
; CHECK-NEXT: entry:
-; CHECK-NEXT: switch i32 [[X:%.*]], label [[EXIT_1:%.*]] [
-; CHECK-NEXT: i32 6, label [[EXIT_2:%.*]]
-; CHECK-NEXT: i32 10, label [[EXIT_3:%.*]]
+; CHECK-NEXT: switch i8 [[X:%.*]], label [[EXIT_1:%.*]] [
+; CHECK-NEXT: i8 6, label [[EXIT_2:%.*]]
+; CHECK-NEXT: i8 10, label [[EXIT_3:%.*]]
; CHECK-NEXT: ]
; CHECK: exit.1:
-; CHECK-NEXT: [[C_1:%.*]] = icmp ult i32 [[X]], 7
-; CHECK-NEXT: [[C_2:%.*]] = icmp ult i32 [[X]], 6
+; CHECK-NEXT: [[C_1:%.*]] = icmp ult i8 [[X]], 7
+; CHECK-NEXT: [[C_2:%.*]] = icmp ult i8 [[X]], 6
; CHECK-NEXT: [[RES_1:%.*]] = xor i1 [[C_1]], [[C_2]]
; CHECK-NEXT: ret i1 [[RES_1]]
; CHECK: exit.2:
-; CHECK-NEXT: [[T_1:%.*]] = icmp ult i32 [[X]], 7
-; CHECK-NEXT: [[F_1:%.*]] = icmp ult i32 [[X]], 6
+; CHECK-NEXT: [[T_1:%.*]] = icmp ult i8 [[X]], 7
+; CHECK-NEXT: [[F_1:%.*]] = icmp ult i8 [[X]], 6
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[T_1]], [[F_1]]
; CHECK-NEXT: ret i1 [[RES_2]]
; CHECK: exit.3:
-; CHECK-NEXT: [[T_2:%.*]] = icmp ult i32 [[X]], 11
-; CHECK-NEXT: [[F_2:%.*]] = icmp ult i32 [[X]], 10
+; CHECK-NEXT: [[T_2:%.*]] = icmp ult i8 [[X]], 11
+; CHECK-NEXT: [[F_2:%.*]] = icmp ult i8 [[X]], 10
; CHECK-NEXT: [[RES_3:%.*]] = xor i1 [[T_2]], [[F_2]]
; CHECK-NEXT: ret i1 [[RES_3]]
;
entry:
- switch i32 %x, label %exit.1 [
- i32 6, label %exit.2
- i32 10, label %exit.3
+ switch i8 %x, label %exit.1 [
+ i8 6, label %exit.2
+ i8 10, label %exit.3
]
exit.1:
- %c.1 = icmp ult i32 %x, 7
- %c.2 = icmp ult i32 %x, 6
+ %c.1 = icmp ult i8 %x, 7
+ %c.2 = icmp ult i8 %x, 6
%res.1 = xor i1 %c.1, %c.2
ret i1 %res.1
exit.2:
- %t.1 = icmp ult i32 %x, 7
- %f.1 = icmp ult i32 %x, 6
+ %t.1 = icmp ult i8 %x, 7
+ %f.1 = icmp ult i8 %x, 6
%res.2 = xor i1 %t.1, %f.1
ret i1 %res.2
exit.3:
- %t.2 = icmp ult i32 %x, 11
- %f.2 = icmp ult i32 %x, 10
+ %t.2 = icmp ult i8 %x, 11
+ %f.2 = icmp ult i8 %x, 10
%res.3 = xor i1 %t.2, %f.2
ret i1 %res.3
}
-define i1 @simplify_based_on_switch_successor_branches(i32 %x) {
+define i1 @simplify_based_on_switch_successor_branches(i8 %x) {
; CHECK-LABEL: @simplify_based_on_switch_successor_branches(
; CHECK-NEXT: entry:
-; CHECK-NEXT: switch i32 [[X:%.*]], label [[EXIT_1:%.*]] [
-; CHECK-NEXT: i32 6, label [[EXIT_2:%.*]]
-; CHECK-NEXT: i32 10, label [[EXIT_3:%.*]]
+; CHECK-NEXT: switch i8 [[X:%.*]], label [[EXIT_1:%.*]] [
+; CHECK-NEXT: i8 6, label [[EXIT_2:%.*]]
+; CHECK-NEXT: i8 10, label [[EXIT_3:%.*]]
; CHECK-NEXT: ]
; CHECK: exit.1:
-; CHECK-NEXT: [[C_1:%.*]] = icmp ult i32 [[X]], 7
-; CHECK-NEXT: [[C_2:%.*]] = icmp ult i32 [[X]], 6
+; CHECK-NEXT: [[C_1:%.*]] = icmp ult i8 [[X]], 7
+; CHECK-NEXT: [[C_2:%.*]] = icmp ult i8 [[X]], 6
; CHECK-NEXT: [[RES_1:%.*]] = xor i1 [[C_1]], [[C_2]]
; CHECK-NEXT: ret i1 [[RES_1]]
; CHECK: exit.2:
-; CHECK-NEXT: [[T_1:%.*]] = icmp ult i32 [[X]], 7
-; CHECK-NEXT: [[F_1:%.*]] = icmp ult i32 [[X]], 6
+; CHECK-NEXT: [[T_1:%.*]] = icmp ult i8 [[X]], 7
+; CHECK-NEXT: [[F_1:%.*]] = icmp ult i8 [[X]], 6
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[T_1]], [[F_1]]
; CHECK-NEXT: call void @use(i1 [[RES_2]])
; CHECK-NEXT: br label [[EXIT_3]]
; CHECK: exit.3:
-; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[X]], 11
-; CHECK-NEXT: [[C_4:%.*]] = icmp ult i32 [[X]], 10
+; CHECK-NEXT: [[C_3:%.*]] = icmp ult i8 [[X]], 11
+; CHECK-NEXT: [[C_4:%.*]] = icmp ult i8 [[X]], 10
; CHECK-NEXT: [[RES_3:%.*]] = xor i1 [[C_3]], [[C_4]]
; CHECK-NEXT: ret i1 [[RES_3]]
;
entry:
- switch i32 %x, label %exit.1 [
- i32 6, label %exit.2
- i32 10, label %exit.3
+ switch i8 %x, label %exit.1 [
+ i8 6, label %exit.2
+ i8 10, label %exit.3
]
exit.1:
- %c.1 = icmp ult i32 %x, 7
- %c.2 = icmp ult i32 %x, 6
+ %c.1 = icmp ult i8 %x, 7
+ %c.2 = icmp ult i8 %x, 6
%res.1 = xor i1 %c.1, %c.2
ret i1 %res.1
exit.2:
- %t.1 = icmp ult i32 %x, 7
- %f.1 = icmp ult i32 %x, 6
+ %t.1 = icmp ult i8 %x, 7
+ %f.1 = icmp ult i8 %x, 6
%res.2 = xor i1 %t.1, %f.1
call void @use(i1 %res.2)
br label %exit.3
exit.3:
- %c.3 = icmp ult i32 %x, 11
- %c.4 = icmp ult i32 %x, 10
+ %c.3 = icmp ult i8 %x, 11
+ %c.4 = icmp ult i8 %x, 10
%res.3 = xor i1 %c.3, %c.4
ret i1 %res.3
}
+define i1 @switch_same_destination_for_
diff erent_cases(i8 %x) {
+; CHECK-LABEL: @switch_same_destination_for_
diff erent_cases(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: switch i8 [[X:%.*]], label [[EXIT_1:%.*]] [
+; CHECK-NEXT: i8 6, label [[EXIT_2:%.*]]
+; CHECK-NEXT: i8 10, label [[EXIT_2]]
+; CHECK-NEXT: ]
+; CHECK: exit.1:
+; CHECK-NEXT: [[C_1:%.*]] = icmp ult i8 [[X]], 7
+; CHECK-NEXT: [[C_2:%.*]] = icmp ult i8 [[X]], 6
+; CHECK-NEXT: [[RES_1:%.*]] = xor i1 [[C_1]], [[C_2]]
+; CHECK-NEXT: ret i1 [[RES_1]]
+; CHECK: exit.2:
+; CHECK-NEXT: [[C_3:%.*]] = icmp ult i8 [[X]], 7
+; CHECK-NEXT: call void @use(i1 [[C_3]])
+; CHECK-NEXT: [[C_4:%.*]] = icmp ult i8 [[X]], 6
+; CHECK-NEXT: call void @use(i1 [[C_4]])
+; CHECK-NEXT: [[C_5:%.*]] = icmp ult i8 [[X]], 11
+; CHECK-NEXT: call void @use(i1 [[C_5]])
+; CHECK-NEXT: [[C_6:%.*]] = icmp ult i8 [[X]], 10
+; CHECK-NEXT: ret i1 [[C_6]]
+;
+entry:
+ switch i8 %x, label %exit.1 [
+ i8 6, label %exit.2
+ i8 10, label %exit.2
+ ]
+
+exit.1:
+ %c.1 = icmp ult i8 %x, 7
+ %c.2 = icmp ult i8 %x, 6
+ %res.1 = xor i1 %c.1, %c.2
+ ret i1 %res.1
+
+exit.2:
+ %c.3 = icmp ult i8 %x, 7
+ call void @use(i1 %c.3)
+ %c.4 = icmp ult i8 %x, 6
+ call void @use(i1 %c.4)
+ %c.5 = icmp ult i8 %x, 11
+ call void @use(i1 %c.5)
+ %c.6 = icmp ult i8 %x, 10
+ ret i1 %c.6
+}
+
declare void @use(i1)
More information about the llvm-commits
mailing list