-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Transform] Rewrite LowerSwitch using APInt
This rewrite fixes #59316. Previously LowerSwitch uses int64_t, which will crash on case branches using integers with more than 64 bits. Using APInt fixes this problem. This patch also includes a test Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D140747
- Loading branch information
1 parent
c3ab645
commit 1db51d8
Showing
2 changed files
with
115 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py | ||
; RUN: opt < %s -passes=lowerswitch -S | FileCheck %s | ||
|
||
define i64 @f(i1 %bool, i128 %i128) { | ||
; CHECK-LABEL: @f( | ||
; CHECK-NEXT: BB: | ||
; CHECK-NEXT: br label [[NODEBLOCK1:%.*]] | ||
; CHECK: NodeBlock1: | ||
; CHECK-NEXT: [[PIVOT2:%.*]] = icmp slt i128 [[I128:%.*]], 16201310291018008446 | ||
; CHECK-NEXT: br i1 [[PIVOT2]], label [[LEAFBLOCK:%.*]], label [[NODEBLOCK:%.*]] | ||
; CHECK: NodeBlock: | ||
; CHECK-NEXT: [[PIVOT:%.*]] = icmp slt i128 [[I128]], 16201310291018008447 | ||
; CHECK-NEXT: br i1 [[PIVOT]], label [[SW_C3:%.*]], label [[SW_C2:%.*]] | ||
; CHECK: LeafBlock: | ||
; CHECK-NEXT: [[SWITCHLEAF:%.*]] = icmp eq i128 [[I128]], 16201310291018008445 | ||
; CHECK-NEXT: br i1 [[SWITCHLEAF]], label [[SW_C4:%.*]], label [[SW_C1:%.*]] | ||
; CHECK: BB1: | ||
; CHECK-NEXT: unreachable | ||
; CHECK: SW_C1: | ||
; CHECK-NEXT: br i1 [[BOOL:%.*]], label [[BB1:%.*]], label [[SW_C1]] | ||
; CHECK: SW_C2: | ||
; CHECK-NEXT: ret i64 0 | ||
; CHECK: SW_C3: | ||
; CHECK-NEXT: ret i64 1 | ||
; CHECK: SW_C4: | ||
; CHECK-NEXT: ret i64 2 | ||
; | ||
BB: | ||
switch i128 %i128, label %BB1 [ | ||
i128 627, label %SW_C1 | ||
i128 16201310291018008447, label %SW_C2 | ||
i128 16201310291018008446, label %SW_C3 | ||
i128 16201310291018008445, label %SW_C4 | ||
] | ||
|
||
BB1: ; preds = %SW_C1, %BB | ||
unreachable | ||
|
||
SW_C1: ; preds = %SW_C1, %BB | ||
br i1 %bool, label %BB1, label %SW_C1 | ||
|
||
SW_C2: ; preds = %BB | ||
ret i64 0 | ||
|
||
SW_C3: ; preds = %BB | ||
ret i64 1 | ||
|
||
SW_C4: ; preds = %BB | ||
ret i64 2 | ||
} | ||
|
||
define i64 @f_empty(i1 %bool, i128 %i128) { | ||
; CHECK-LABEL: @f_empty( | ||
; CHECK-NEXT: BB: | ||
; CHECK-NEXT: br label [[BB1:%.*]] | ||
; CHECK: BB1: | ||
; CHECK-NEXT: unreachable | ||
; | ||
BB: | ||
switch i128 %i128, label %BB1 [] | ||
|
||
BB1: ; preds = %BB | ||
unreachable | ||
} |