Skip to content

Commit c0ef806

Browse files
committed
[LoopIdiom] Strip exotic scenario
1 parent 727ef42 commit c0ef806

File tree

2 files changed

+28
-52
lines changed

2 files changed

+28
-52
lines changed

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,12 +1545,6 @@ bool LoopIdiomRecognize::optimizeCRCLoop(const PolynomialInfo &Info) {
15451545
if (TT.getArch() == Triple::hexagon)
15461546
return false;
15471547

1548-
// Check that the DataLayout allows us to index into the new 256-entry CRC
1549-
// table.
1550-
Type *IdxTy = SE->getDataLayout().getIndexType(M.getContext(), 0);
1551-
if (IdxTy->getIntegerBitWidth() < 8)
1552-
return false;
1553-
15541548
// First, create a new GlobalVariable corresponding to the
15551549
// Sarwate-lookup-table.
15561550
Type *CRCTy = Info.LHS->getType();
@@ -1657,7 +1651,9 @@ bool LoopIdiomRecognize::optimizeCRCLoop(const PolynomialInfo &Info) {
16571651
: LoByte(Builder, Indexer, "indexer.lo");
16581652

16591653
// Always index into a GEP using the index type.
1660-
Indexer = Builder.CreateZExt(Indexer, IdxTy, "indexer.ext");
1654+
Indexer = Builder.CreateZExt(
1655+
Indexer, SE->getDataLayout().getIndexType(GV->getType()),
1656+
"indexer.ext");
16611657

16621658
// CRCTableLd = CRCTable[(iv'th byte of data) ^ (top|bottom) byte of CRC].
16631659
Value *CRCTableGEP =

llvm/test/Transforms/LoopIdiom/cyclic-redundancy-check-dl.ll

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,33 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 6
2-
; RUN: opt -passes=loop-idiom -data-layout="p:16:16" -S %s | FileCheck %s --check-prefix=CHECK-i16
3-
; RUN: opt -passes=loop-idiom -data-layout="p:1:8" -S %s | FileCheck %s --check-prefix=CHECK-i1
2+
; RUN: opt -passes=loop-idiom -S %s | FileCheck %s
3+
4+
target datalayout = "p:16:16"
45

56
;.
6-
; CHECK-i16: @.crctable = private constant [256 x i32] zeroinitializer
7+
; CHECK: @.crctable = private constant [256 x i32] zeroinitializer
78
;.
89
define void @test_with_dl() {
9-
; CHECK-i16-LABEL: define void @test_with_dl() {
10-
; CHECK-i16-NEXT: [[ENTRY:.*]]:
11-
; CHECK-i16-NEXT: br label %[[PH:.*]]
12-
; CHECK-i16: [[PH_LOOPEXIT:.*]]:
13-
; CHECK-i16-NEXT: [[CRC_NEXT_LCSSA:%.*]] = phi i32 [ [[CRC_NEXT3:%.*]], %[[LOOP:.*]] ]
14-
; CHECK-i16-NEXT: br label %[[PH]]
15-
; CHECK-i16: [[PH]]:
16-
; CHECK-i16-NEXT: [[CRC_USE:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[CRC_NEXT_LCSSA]], %[[PH_LOOPEXIT]] ]
17-
; CHECK-i16-NEXT: br label %[[LOOP]]
18-
; CHECK-i16: [[LOOP]]:
19-
; CHECK-i16-NEXT: [[IV:%.*]] = phi i16 [ 0, %[[PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
20-
; CHECK-i16-NEXT: [[CRC2:%.*]] = phi i32 [ 0, %[[PH]] ], [ [[CRC_NEXT3]], %[[LOOP]] ]
21-
; CHECK-i16-NEXT: [[TMP0:%.*]] = trunc i32 [[CRC2]] to i8
22-
; CHECK-i16-NEXT: [[INDEXER_EXT:%.*]] = zext i8 [[TMP0]] to i16
23-
; CHECK-i16-NEXT: [[TBL_PTRADD:%.*]] = getelementptr inbounds i32, ptr @.crctable, i16 [[INDEXER_EXT]]
24-
; CHECK-i16-NEXT: [[TBL_LD:%.*]] = load i32, ptr [[TBL_PTRADD]], align 4
25-
; CHECK-i16-NEXT: [[CRC_LE_SHIFT:%.*]] = lshr i32 [[CRC2]], 8
26-
; CHECK-i16-NEXT: [[CRC_NEXT3]] = xor i32 [[CRC_LE_SHIFT]], [[TBL_LD]]
27-
; CHECK-i16-NEXT: [[IV_NEXT]] = add i16 [[IV]], 1
28-
; CHECK-i16-NEXT: [[EXIT_COND1:%.*]] = icmp ne i16 [[IV]], 0
29-
; CHECK-i16-NEXT: br i1 [[EXIT_COND1]], label %[[LOOP]], label %[[PH_LOOPEXIT]]
30-
;
31-
; CHECK-i1-LABEL: define void @test_with_dl() {
32-
; CHECK-i1-NEXT: [[ENTRY:.*]]:
33-
; CHECK-i1-NEXT: br label %[[PH:.*]]
34-
; CHECK-i1: [[PH_LOOPEXIT:.*]]:
35-
; CHECK-i1-NEXT: [[CRC_NEXT_LCSSA:%.*]] = phi i32 [ [[CRC_NEXT:%.*]], %[[LOOP:.*]] ]
36-
; CHECK-i1-NEXT: br label %[[PH]]
37-
; CHECK-i1: [[PH]]:
38-
; CHECK-i1-NEXT: [[CRC_USE:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[CRC_NEXT_LCSSA]], %[[PH_LOOPEXIT]] ]
39-
; CHECK-i1-NEXT: br label %[[LOOP]]
40-
; CHECK-i1: [[LOOP]]:
41-
; CHECK-i1-NEXT: [[IV:%.*]] = phi i16 [ 0, %[[PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
42-
; CHECK-i1-NEXT: [[CRC:%.*]] = phi i32 [ 0, %[[PH]] ], [ [[CRC_NEXT]], %[[LOOP]] ]
43-
; CHECK-i1-NEXT: [[LSHR_CRC_1:%.*]] = lshr i32 [[CRC]], 1
44-
; CHECK-i1-NEXT: [[CRC_AND_1:%.*]] = and i32 [[CRC]], 1
45-
; CHECK-i1-NEXT: [[SB_CHECK:%.*]] = icmp eq i32 [[CRC_AND_1]], 0
46-
; CHECK-i1-NEXT: [[XOR:%.*]] = xor i32 [[LSHR_CRC_1]], 0
47-
; CHECK-i1-NEXT: [[CRC_NEXT]] = select i1 [[SB_CHECK]], i32 [[LSHR_CRC_1]], i32 [[XOR]]
48-
; CHECK-i1-NEXT: [[IV_NEXT]] = add i16 [[IV]], 1
49-
; CHECK-i1-NEXT: [[EXIT_COND:%.*]] = icmp ult i16 [[IV]], 7
50-
; CHECK-i1-NEXT: br i1 [[EXIT_COND]], label %[[LOOP]], label %[[PH_LOOPEXIT]]
10+
; CHECK-LABEL: define void @test_with_dl() {
11+
; CHECK-NEXT: [[ENTRY:.*]]:
12+
; CHECK-NEXT: br label %[[PH:.*]]
13+
; CHECK: [[PH_LOOPEXIT:.*]]:
14+
; CHECK-NEXT: [[CRC_NEXT_LCSSA:%.*]] = phi i32 [ [[CRC_NEXT3:%.*]], %[[LOOP:.*]] ]
15+
; CHECK-NEXT: br label %[[PH]]
16+
; CHECK: [[PH]]:
17+
; CHECK-NEXT: [[CRC_USE:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[CRC_NEXT_LCSSA]], %[[PH_LOOPEXIT]] ]
18+
; CHECK-NEXT: br label %[[LOOP]]
19+
; CHECK: [[LOOP]]:
20+
; CHECK-NEXT: [[IV:%.*]] = phi i16 [ 0, %[[PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
21+
; CHECK-NEXT: [[CRC2:%.*]] = phi i32 [ 0, %[[PH]] ], [ [[CRC_NEXT3]], %[[LOOP]] ]
22+
; CHECK-NEXT: [[TMP0:%.*]] = trunc i32 [[CRC2]] to i8
23+
; CHECK-NEXT: [[INDEXER_EXT:%.*]] = zext i8 [[TMP0]] to i16
24+
; CHECK-NEXT: [[TBL_PTRADD:%.*]] = getelementptr inbounds i32, ptr @.crctable, i16 [[INDEXER_EXT]]
25+
; CHECK-NEXT: [[TBL_LD:%.*]] = load i32, ptr [[TBL_PTRADD]], align 4
26+
; CHECK-NEXT: [[CRC_LE_SHIFT:%.*]] = lshr i32 [[CRC2]], 8
27+
; CHECK-NEXT: [[CRC_NEXT3]] = xor i32 [[CRC_LE_SHIFT]], [[TBL_LD]]
28+
; CHECK-NEXT: [[IV_NEXT]] = add i16 [[IV]], 1
29+
; CHECK-NEXT: [[EXIT_COND1:%.*]] = icmp ne i16 [[IV]], 0
30+
; CHECK-NEXT: br i1 [[EXIT_COND1]], label %[[LOOP]], label %[[PH_LOOPEXIT]]
5131
;
5232
entry:
5333
br label %ph

0 commit comments

Comments
 (0)