• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; REQUIRES: aarch64-registered-target
2; RUN: opt < %s -codegenprepare -mtriple=arm64-apple-ios -S | FileCheck %s
3
4@first_ones = external global [65536 x i8]
5
6define i32 @fct19(i64 %arg1) #0 !dbg !6 {
7; CHECK-LABEL: @fct19
8entry:
9  %x.sroa.1.0.extract.shift = lshr i64 %arg1, 16, !dbg !35
10  %x.sroa.1.0.extract.trunc = trunc i64 %x.sroa.1.0.extract.shift to i16, !dbg !36
11
12  %x.sroa.3.0.extract.shift = lshr i64 %arg1, 32, !dbg !37
13  call void @llvm.dbg.value(metadata i64 %x.sroa.3.0.extract.shift, metadata !13, metadata !DIExpression()), !dbg !37
14; CHECK: call void @llvm.dbg.value(metadata i64 %arg1, metadata {{.*}}, metadata !DIExpression(DW_OP_constu, 32, DW_OP_shr, DW_OP_stack_value)), !dbg [[shift2_loc:![0-9]+]]
15
16  %x.sroa.5.0.extract.shift = lshr i64 %arg1, 48, !dbg !38
17  %tobool = icmp eq i64 %x.sroa.5.0.extract.shift, 0, !dbg !39
18  br i1 %tobool, label %if.end, label %if.then, !dbg !40
19
20if.then:                                          ; preds = %entry
21  %arrayidx3 = getelementptr inbounds [65536 x i8], [65536 x i8]* @first_ones, i64 0, i64 %x.sroa.5.0.extract.shift, !dbg !41
22  %0 = load i8, i8* %arrayidx3, align 1, !dbg !42
23  %conv = zext i8 %0 to i32, !dbg !43
24  br label %return, !dbg !44
25
26if.end:                                           ; preds = %entry
27; CHECK-LABEL: if.end:
28; CHECK-NEXT: lshr i64 %arg1, 32, !dbg [[shift2_loc]]
29  %x.sroa.3.0.extract.trunc = trunc i64 %x.sroa.3.0.extract.shift to i16, !dbg !45
30  %tobool6 = icmp eq i16 %x.sroa.3.0.extract.trunc, 0, !dbg !46
31  br i1 %tobool6, label %if.end13, label %if.then7, !dbg !47
32
33if.then7:                                         ; preds = %if.end
34  %idxprom10 = and i64 %x.sroa.3.0.extract.shift, 65535, !dbg !48
35  %arrayidx11 = getelementptr inbounds [65536 x i8], [65536 x i8]* @first_ones, i64 0, i64 %idxprom10, !dbg !49
36  %1 = load i8, i8* %arrayidx11, align 1, !dbg !50
37  %conv12 = zext i8 %1 to i32, !dbg !51
38  %add = add nsw i32 %conv12, 16, !dbg !52
39  br label %return, !dbg !53
40
41if.end13:                                         ; preds = %if.end
42; CHECK-LABEL: if.end13:
43; CHECK-NEXT: [[shift1:%.*]] = lshr i64 %arg1, 16, !dbg [[shift1_loc:![0-9]+]]
44; CHECK-NEXT: trunc i64 [[shift1]] to i16, !dbg [[trunc1_loc:![0-9]+]]
45  %tobool16 = icmp eq i16 %x.sroa.1.0.extract.trunc, 0, !dbg !54
46  br i1 %tobool16, label %return, label %if.then17, !dbg !55
47
48if.then17:                                        ; preds = %if.end13
49  %idxprom20 = and i64 %x.sroa.1.0.extract.shift, 65535, !dbg !56
50  %arrayidx21 = getelementptr inbounds [65536 x i8], [65536 x i8]* @first_ones, i64 0, i64 %idxprom20, !dbg !57
51  %2 = load i8, i8* %arrayidx21, align 1, !dbg !58
52  %conv22 = zext i8 %2 to i32, !dbg !59
53  %add23 = add nsw i32 %conv22, 32, !dbg !60
54  br label %return, !dbg !61
55
56return:                                           ; preds = %if.then17, %if.end13, %if.then7, %if.then
57  %retval.0 = phi i32 [ %conv, %if.then ], [ %add, %if.then7 ], [ %add23, %if.then17 ], [ 64, %if.end13 ], !dbg !62
58  ret i32 %retval.0, !dbg !63
59}
60
61; CodeGenPrepare was erasing the unused lshr instruction, but then further
62; processing the instruction after it was freed. If this bug is still present,
63; this test will always crash in an LLVM built with ASAN enabled, and may
64; crash even if ASAN is not enabled.
65
66define i32 @shift_unused(i32 %a) {
67; CHECK-LABEL: @shift_unused(
68; CHECK-NEXT:  BB2:
69; CHECK-NEXT:    ret i32 [[A:%.*]]
70;
71  %as = lshr i32 %a, 3
72  br label %BB2
73
74BB2:
75  ret i32 %a
76}
77
78; CHECK: [[shift1_loc]] = !DILocation(line: 1
79; CHECK: [[trunc1_loc]] = !DILocation(line: 2
80; CHECK: [[shift2_loc]] = !DILocation(line: 3
81
82declare void @llvm.dbg.value(metadata, metadata, metadata) #1
83
84attributes #0 = { nounwind readonly ssp }
85attributes #1 = { nounwind readnone speculatable }
86
87!llvm.dbg.cu = !{!0}
88!llvm.module.flags = !{!5}
89
90!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
91!1 = !DIFile(filename: "sink-shift-and-trunc.ll", directory: "/")
92!2 = !{}
93!5 = !{i32 2, !"Debug Info Version", i32 3}
94!6 = distinct !DISubprogram(name: "fct19", linkageName: "fct19", scope: null, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, retainedNodes: !8)
95!7 = !DISubroutineType(types: !2)
96!8 = !{!13}
97!10 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned)
98!13 = !DILocalVariable(name: "3", scope: !6, file: !1, line: 3, type: !10)
99!35 = !DILocation(line: 1, column: 1, scope: !6)
100!36 = !DILocation(line: 2, column: 1, scope: !6)
101!37 = !DILocation(line: 3, column: 1, scope: !6)
102!38 = !DILocation(line: 4, column: 1, scope: !6)
103!39 = !DILocation(line: 5, column: 1, scope: !6)
104!40 = !DILocation(line: 6, column: 1, scope: !6)
105!41 = !DILocation(line: 7, column: 1, scope: !6)
106!42 = !DILocation(line: 8, column: 1, scope: !6)
107!43 = !DILocation(line: 9, column: 1, scope: !6)
108!44 = !DILocation(line: 10, column: 1, scope: !6)
109!45 = !DILocation(line: 11, column: 1, scope: !6)
110!46 = !DILocation(line: 12, column: 1, scope: !6)
111!47 = !DILocation(line: 13, column: 1, scope: !6)
112!48 = !DILocation(line: 14, column: 1, scope: !6)
113!49 = !DILocation(line: 15, column: 1, scope: !6)
114!50 = !DILocation(line: 16, column: 1, scope: !6)
115!51 = !DILocation(line: 17, column: 1, scope: !6)
116!52 = !DILocation(line: 18, column: 1, scope: !6)
117!53 = !DILocation(line: 19, column: 1, scope: !6)
118!54 = !DILocation(line: 20, column: 1, scope: !6)
119!55 = !DILocation(line: 21, column: 1, scope: !6)
120!56 = !DILocation(line: 22, column: 1, scope: !6)
121!57 = !DILocation(line: 23, column: 1, scope: !6)
122!58 = !DILocation(line: 24, column: 1, scope: !6)
123!59 = !DILocation(line: 25, column: 1, scope: !6)
124!60 = !DILocation(line: 26, column: 1, scope: !6)
125!61 = !DILocation(line: 27, column: 1, scope: !6)
126!62 = !DILocation(line: 28, column: 1, scope: !6)
127!63 = !DILocation(line: 29, column: 1, scope: !6)
128