[llvm] [SimplifyCFG] Find the minimal table considering overflow in `switchToLookupTable` (PR #67885)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 30 23:28:02 PDT 2023
================
@@ -1776,11 +1878,10 @@ define i32 @signed_overflow_negative(i8 %n) {
; CHECK-LABEL: @signed_overflow_negative(
; CHECK-NEXT: start:
; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[N:%.*]] to i2
-; CHECK-NEXT: [[SWITCH_TABLEIDX:%.*]] = sub i2 [[TRUNC]], -2
-; CHECK-NEXT: [[SWITCH_IDX_CAST:%.*]] = zext i2 [[SWITCH_TABLEIDX]] to i32
-; CHECK-NEXT: [[SWITCH_IDX_MULT:%.*]] = mul nsw i32 [[SWITCH_IDX_CAST]], 1111
-; CHECK-NEXT: [[SWITCH_OFFSET:%.*]] = add nsw i32 [[SWITCH_IDX_MULT]], 1111
-; CHECK-NEXT: ret i32 [[SWITCH_OFFSET]]
+; CHECK-NEXT: [[SWITCH_TABLEIDX_ZEXT:%.*]] = zext i2 [[TRUNC]] to i3
----------------
DianQK wrote:
`signed_overflow1` is the opposite example. So I think it was just a lucky result.
I think this should be another optimization. After this PR, the minimal table provides all the valid index values. Then select the optimal index value on the `ShouldUseSwitchConditionAsTableIndex` and `SwitchLookupTable::BuildLookup`.
https://github.com/llvm/llvm-project/pull/67885
More information about the llvm-commits
mailing list