Skip to content

Commit 73929c4

Browse files
committed
[LoopIdiomRecognize] @llvm.dbg values shouldn't affect the transformation.
Summary: PR40564 Reviewers: aprantl, rnk Subscribers: llvm-commits, hiraditya Tags: #llvm Differential Revision: https://reviews.llvm.org/D57629 llvm-svn: 353007
1 parent e64aee8 commit 73929c4

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,9 +1460,15 @@ bool LoopIdiomRecognize::recognizeAndInsertFFS() {
14601460
const Value *Args[] =
14611461
{InitX, ZeroCheck ? ConstantInt::getTrue(InitX->getContext())
14621462
: ConstantInt::getFalse(InitX->getContext())};
1463-
if (CurLoop->getHeader()->size() != IdiomCanonicalSize &&
1463+
1464+
// @llvm.dbg doesn't count as they have no semantic effect.
1465+
auto InstWithoutDebugIt = CurLoop->getHeader()->instructionsWithoutDebug();
1466+
uint32_t HeaderSize =
1467+
std::distance(InstWithoutDebugIt.begin(), InstWithoutDebugIt.end());
1468+
1469+
if (HeaderSize != IdiomCanonicalSize &&
14641470
TTI->getIntrinsicCost(IntrinID, InitX->getType(), Args) >
1465-
TargetTransformInfo::TCC_Basic)
1471+
TargetTransformInfo::TCC_Basic)
14661472
return false;
14671473

14681474
transformLoopToCountable(IntrinID, PH, CntInst, CntPhi, InitX, DefX,
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
; RUN: opt -S -loop-idiom -mtriple=systemz-unknown -mcpu=z13 %s | FileCheck %s
2+
3+
; CHECK: @llvm.ctlz.i32
4+
5+
declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
6+
define dso_local i32 @CeilLog2(i32 %arg) local_unnamed_addr #1 !dbg !38 {
7+
bb:
8+
%tmp4 = add i32 %arg, -1, !dbg !45
9+
call void @llvm.dbg.value(metadata i32 0, metadata !44, metadata !DIExpression()), !dbg !45
10+
%tmp71 = icmp eq i32 %tmp4, 0, !dbg !45
11+
br i1 %tmp71, label %bb13, label %bb8.preheader, !dbg !48
12+
13+
bb8.preheader: ; preds = %bb
14+
br label %bb8, !dbg !49
15+
16+
bb8: ; preds = %bb8.preheader, %bb8
17+
%tmp2.03 = phi i32 [ %tmp12, %bb8 ], [ 0, %bb8.preheader ]
18+
%tmp1.02 = phi i32 [ %tmp10, %bb8 ], [ %tmp4, %bb8.preheader ]
19+
call void @llvm.dbg.value(metadata i32 %tmp2.03, metadata !44, metadata !DIExpression()), !dbg !45
20+
%tmp10 = lshr i32 %tmp1.02, 1, !dbg !49
21+
%tmp12 = add nuw nsw i32 %tmp2.03, 1, !dbg !51
22+
call void @llvm.dbg.value(metadata i32 %tmp12, metadata !44, metadata !DIExpression()), !dbg !45
23+
%tmp7 = icmp eq i32 %tmp10, 0, !dbg !45
24+
br i1 %tmp7, label %bb13.loopexit, label %bb8, !dbg !48, !llvm.loop !52
25+
26+
bb13.loopexit: ; preds = %bb8
27+
%tmp12.lcssa = phi i32 [ %tmp12, %bb8 ], !dbg !51
28+
br label %bb13, !dbg !54
29+
30+
bb13: ; preds = %bb13.loopexit, %bb
31+
%tmp2.0.lcssa = phi i32 [ 0, %bb ], [ %tmp12.lcssa, %bb13.loopexit ], !dbg !55
32+
call void @llvm.dbg.value(metadata i32 %tmp2.0.lcssa, metadata !44, metadata !DIExpression()), !dbg !45
33+
ret i32 %tmp2.0.lcssa, !dbg !54
34+
}
35+
36+
; Function Attrs: nounwind readnone speculatable
37+
declare void @llvm.dbg.value(metadata, metadata, metadata) #2
38+
39+
attributes #0 = { nounwind readnone speculatable "target-cpu"="z13" }
40+
attributes #1 = { norecurse nounwind readnone "target-cpu"="z13" "use-soft-float"="false" }
41+
attributes #2 = { nounwind readnone speculatable }
42+
43+
!llvm.dbg.cu = !{!0}
44+
!llvm.module.flags = !{!36, !37}
45+
46+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 ([email protected]:llvm/llvm-dev-2/tools/clang a87ff88c6466fbedd6281513b9480a2cad6c08c8) (llvm/llvm-dev-2 922a3b1b3254bf3310c467e880a5419c1e13c87f)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, nameTableKind: None)
47+
!1 = !DIFile(filename: "configfile.c", directory: "/home/ijonpan/minispec-2006/spec-llvm/464.h264ref/build")
48+
!2 = !{}
49+
!4 = !DIFile(filename: "./global.h", directory: "/home/ijonpan/minispec-2006/spec-llvm/464.h264ref/build")
50+
!5 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
51+
!36 = !{i32 2, !"Debug Info Version", i32 3}
52+
!37 = !{i32 1, !"wchar_size", i32 4}
53+
!38 = distinct !DISubprogram(name: "CeilLog2", scope: !1, file: !1, line: 599, type: !39, scopeLine: 600, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !41)
54+
!39 = !DISubroutineType(types: !40)
55+
!40 = !{!5, !5}
56+
!41 = !{!42, !43, !44}
57+
!42 = !DILocalVariable(name: "uiVal", arg: 1, scope: !38, file: !1, line: 599, type: !5)
58+
!43 = !DILocalVariable(name: "uiTmp", scope: !38, file: !1, line: 601, type: !5)
59+
!44 = !DILocalVariable(name: "uiRet", scope: !38, file: !1, line: 602, type: !5)
60+
!45 = !DILocation(line: 601, column: 25, scope: !38)
61+
!48 = !DILocation(line: 604, column: 3, scope: !38)
62+
!49 = !DILocation(line: 606, column: 11, scope: !50)
63+
!50 = distinct !DILexicalBlock(scope: !38, file: !1, line: 605, column: 3)
64+
!51 = !DILocation(line: 607, column: 10, scope: !50)
65+
!52 = distinct !{!52, !48, !53}
66+
!53 = !DILocation(line: 608, column: 3, scope: !38)
67+
!54 = !DILocation(line: 609, column: 3, scope: !38)
68+
!55 = !DILocation(line: 0, scope: !38)

0 commit comments

Comments
 (0)