Skip to content

Commit 0e6a181

Browse files
committed
Revert "SimplifyCFG: Delay creation of bitmaps"
This reverts commit 27179dc.
1 parent 913bcb4 commit 0e6a181

File tree

3 files changed

+13
-48
lines changed

3 files changed

+13
-48
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6469,9 +6469,6 @@ class SwitchReplacement {
64696469
/// Return true if the replacement is a lookup table.
64706470
bool isLookupTable();
64716471

6472-
/// Return true if the replacement is a bitmap.
6473-
bool isBitMap();
6474-
64756472
private:
64766473
// Depending on the switch, there are different alternatives.
64776474
enum {
@@ -6762,8 +6759,6 @@ Constant *SwitchReplacement::getDefaultValue() { return DefaultValue; }
67626759

67636760
bool SwitchReplacement::isLookupTable() { return Kind == LookupTableKind; }
67646761

6765-
bool SwitchReplacement::isBitMap() { return Kind == BitMapKind; }
6766-
67676762
static bool isSwitchDense(uint64_t NumCases, uint64_t CaseRange) {
67686763
// 40% is the default density for building a jump table in optsize/minsize
67696764
// mode. See also TargetLoweringBase::isSuitableForJumpTable(), which this
@@ -7113,14 +7108,6 @@ static bool simplifySwitchLookup(SwitchInst *SI, IRBuilder<> &Builder,
71137108
Fn->getFnAttribute("no-jump-tables").getValueAsBool()))
71147109
return false;
71157110

7116-
bool AnyBitMaps = any_of(PhiToReplacementMap,
7117-
[](auto &KV) { return KV.second.isBitMap(); });
7118-
7119-
// Bitmaps can also cause missed optimizations due to difficult-to-analyze
7120-
// code. Delay the creation of bitmaps until later in the pipeline.
7121-
if (AnyBitMaps && !ConvertSwitchToLookupTable)
7122-
return false;
7123-
71247111
Builder.SetInsertPoint(SI);
71257112
// TableIndex is the switch condition - TableIndexOffset if we don't
71267113
// use the condition directly

llvm/test/Transforms/PhaseOrdering/X86/merge-functions.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ bb3: ; preds = %bb1, %bb2
8989

9090
define i1 @test2(i32 %c) {
9191
; CHECK-LABEL: @test2(
92-
; CHECK-NEXT: [[TMP2:%.*]] = tail call noundef i1 @test1(i32 [[TMP0:%.*]]) #[[ATTR0:[0-9]+]]
92+
; CHECK-NEXT: [[TMP2:%.*]] = tail call i1 @test1(i32 [[TMP0:%.*]]) #[[ATTR0:[0-9]+]]
9393
; CHECK-NEXT: ret i1 [[TMP2]]
9494
;
9595
entry:

llvm/test/Transforms/SimplifyCFG/switch-transformations-no-lut.ll

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -166,23 +166,11 @@ end:
166166
define i4 @bitmap_no_default(i32 %x) {
167167
; OPTNOLUT-LABEL: define i4 @bitmap_no_default(
168168
; OPTNOLUT-SAME: i32 [[X:%.*]]) {
169-
; OPTNOLUT-NEXT: [[ENTRY:.*]]:
170-
; OPTNOLUT-NEXT: switch i32 [[X]], label %[[DEFAULT:.*]] [
171-
; OPTNOLUT-NEXT: i32 0, label %[[END:.*]]
172-
; OPTNOLUT-NEXT: i32 1, label %[[CASE1:.*]]
173-
; OPTNOLUT-NEXT: i32 2, label %[[CASE2:.*]]
174-
; OPTNOLUT-NEXT: i32 3, label %[[CASE3:.*]]
175-
; OPTNOLUT-NEXT: ]
176-
; OPTNOLUT: [[CASE1]]:
177-
; OPTNOLUT-NEXT: br label %[[END]]
178-
; OPTNOLUT: [[CASE2]]:
179-
; OPTNOLUT-NEXT: br label %[[END]]
180-
; OPTNOLUT: [[CASE3]]:
181-
; OPTNOLUT-NEXT: br label %[[END]]
182-
; OPTNOLUT: [[DEFAULT]]:
183-
; OPTNOLUT-NEXT: unreachable
184-
; OPTNOLUT: [[END]]:
185-
; OPTNOLUT-NEXT: [[SWITCH_MASKED:%.*]] = phi i4 [ 2, %[[CASE1]] ], [ 4, %[[CASE2]] ], [ -8, %[[CASE3]] ], [ 0, %[[ENTRY]] ]
169+
; OPTNOLUT-NEXT: [[ENTRY:.*:]]
170+
; OPTNOLUT-NEXT: [[SWITCH_CAST:%.*]] = trunc i32 [[X]] to i16
171+
; OPTNOLUT-NEXT: [[SWITCH_SHIFTAMT:%.*]] = mul nuw nsw i16 [[SWITCH_CAST]], 4
172+
; OPTNOLUT-NEXT: [[SWITCH_DOWNSHIFT:%.*]] = lshr i16 -31712, [[SWITCH_SHIFTAMT]]
173+
; OPTNOLUT-NEXT: [[SWITCH_MASKED:%.*]] = trunc i16 [[SWITCH_DOWNSHIFT]] to i4
186174
; OPTNOLUT-NEXT: ret i4 [[SWITCH_MASKED]]
187175
;
188176
; TTINOLUT-LABEL: define i4 @bitmap_no_default(
@@ -221,23 +209,13 @@ end:
221209
define i4 @bitmap_with_default(i32 %x) {
222210
; OPTNOLUT-LABEL: define i4 @bitmap_with_default(
223211
; OPTNOLUT-SAME: i32 [[X:%.*]]) {
224-
; OPTNOLUT-NEXT: [[ENTRY:.*]]:
225-
; OPTNOLUT-NEXT: switch i32 [[X]], label %[[DEFAULT:.*]] [
226-
; OPTNOLUT-NEXT: i32 0, label %[[END:.*]]
227-
; OPTNOLUT-NEXT: i32 1, label %[[CASE1:.*]]
228-
; OPTNOLUT-NEXT: i32 2, label %[[CASE2:.*]]
229-
; OPTNOLUT-NEXT: i32 3, label %[[CASE3:.*]]
230-
; OPTNOLUT-NEXT: ]
231-
; OPTNOLUT: [[CASE1]]:
232-
; OPTNOLUT-NEXT: br label %[[END]]
233-
; OPTNOLUT: [[CASE2]]:
234-
; OPTNOLUT-NEXT: br label %[[END]]
235-
; OPTNOLUT: [[CASE3]]:
236-
; OPTNOLUT-NEXT: br label %[[END]]
237-
; OPTNOLUT: [[DEFAULT]]:
238-
; OPTNOLUT-NEXT: br label %[[END]]
239-
; OPTNOLUT: [[END]]:
240-
; OPTNOLUT-NEXT: [[IDX:%.*]] = phi i4 [ 2, %[[CASE1]] ], [ 4, %[[CASE2]] ], [ -8, %[[CASE3]] ], [ -1, %[[DEFAULT]] ], [ 0, %[[ENTRY]] ]
212+
; OPTNOLUT-NEXT: [[ENTRY:.*:]]
213+
; OPTNOLUT-NEXT: [[TMP0:%.*]] = icmp ult i32 [[X]], 4
214+
; OPTNOLUT-NEXT: [[SWITCH_CAST:%.*]] = trunc i32 [[X]] to i16
215+
; OPTNOLUT-NEXT: [[SWITCH_SHIFTAMT:%.*]] = mul nuw nsw i16 [[SWITCH_CAST]], 4
216+
; OPTNOLUT-NEXT: [[SWITCH_DOWNSHIFT:%.*]] = lshr i16 -31712, [[SWITCH_SHIFTAMT]]
217+
; OPTNOLUT-NEXT: [[SWITCH_MASKED:%.*]] = trunc i16 [[SWITCH_DOWNSHIFT]] to i4
218+
; OPTNOLUT-NEXT: [[IDX:%.*]] = select i1 [[TMP0]], i4 [[SWITCH_MASKED]], i4 -1
241219
; OPTNOLUT-NEXT: ret i4 [[IDX]]
242220
;
243221
; TTINOLUT-LABEL: define i4 @bitmap_with_default(

0 commit comments

Comments
 (0)