Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 15497c1

Browse files
committed
[DAGCombiner] Fix DebugLoc propagation when folding !(x cc y) -> (x !cc y)
Summary: Currently, when 't1: i1 = setcc t2, t3, cc' followed by 't4: i1 = xor t1, Constant:i1<-1>' is folded into 't5: i1 = setcc t2, t3 !cc', SDLoc of newly created SDValue 't5' follows SDLoc of 't4', not 't1'. However, as the opcode of newly created SDValue is 'setcc', it make more sense to take DebugLoc from 't1' than 't4'. For the code below ``` extern int bar(); extern int baz(); int foo(int x, int y) { if (x != y) return bar(); else return baz(); } ``` , following is the bitcode representation of 'foo' at the end of llvm-ir level optimization: ``` define i32 @foo(i32 %x, i32 %y) !dbg !4 { entry: tail call void @llvm.dbg.value(metadata i32 %x, i64 0, metadata !9, metadata !11), !dbg !12 tail call void @llvm.dbg.value(metadata i32 %y, i64 0, metadata !10, metadata !11), !dbg !13 %cmp = icmp ne i32 %x, %y, !dbg !14 br i1 %cmp, label %if.then, label %if.else, !dbg !16 if.then: ; preds = %entry %call = tail call i32 (...) @bar() #3, !dbg !17 br label %return, !dbg !18 if.else: ; preds = %entry %call1 = tail call i32 (...) @baz() #3, !dbg !19 br label %return, !dbg !20 return: ; preds = %if.else, %if.then %retval.0 = phi i32 [ %call, %if.then ], [ %call1, %if.else ] ret i32 %retval.0, !dbg !21 } !14 = !DILocation(line: 5, column: 9, scope: !15) !16 = !DILocation(line: 5, column: 7, scope: !4) ``` As you can see, in 'entry' block, 'icmp' instruction and 'br' instruction have different debug locations. However, with current implementation, there's no distinction between debug locations of these two when they are lowered to asm instructions. This is because 'icmp' and 'br' become 'setcc' 'xor' and 'brcond' in SelectionDAG, where SDLoc of 'setcc' follows the debug location of 'icmp' but SDLOC of 'xor' and 'brcond' follows the debug location of 'br' instruction, and SDLoc of 'xor' overwrites SDLoc of 'setcc' when they are folded. This patch addresses this issue. Reviewers: atrick, bogner, andreadb, craig.topper, aprantl Reviewed By: andreadb Subscribers: jlebar, mkuper, jholewinski, andreadb, llvm-commits Differential Revision: https://reviews.llvm.org/D29813 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296825 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 0eec3b0 commit 15497c1

File tree

6 files changed

+93
-24
lines changed

6 files changed

+93
-24
lines changed

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4856,9 +4856,9 @@ SDValue DAGCombiner::visitXOR(SDNode *N) {
48564856
default:
48574857
llvm_unreachable("Unhandled SetCC Equivalent!");
48584858
case ISD::SETCC:
4859-
return DAG.getSetCC(SDLoc(N), VT, LHS, RHS, NotCC);
4859+
return DAG.getSetCC(SDLoc(N0), VT, LHS, RHS, NotCC);
48604860
case ISD::SELECT_CC:
4861-
return DAG.getSelectCC(SDLoc(N), LHS, RHS, N0.getOperand(2),
4861+
return DAG.getSelectCC(SDLoc(N0), LHS, RHS, N0.getOperand(2),
48624862
N0.getOperand(3), NotCC);
48634863
}
48644864
}

test/CodeGen/NVPTX/lower-aggr-copies.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ entry:
114114

115115
; PTX-LABEL: .visible .func (.param .b64 func_retval0) memmove_caller(
116116
; PTX: ld.param.u64 %rd[[N:[0-9]+]]
117-
; PTX: setp.eq.s64 %p[[NEQ0:[0-9]+]], %rd[[N]], 0
118-
; PTX: setp.ge.u64 %p[[SRC_GT_THAN_DST:[0-9]+]], %rd{{[0-9]+}}, %rd{{[0-9]+}}
117+
; PTX-DAG: setp.eq.s64 %p[[NEQ0:[0-9]+]], %rd[[N]], 0
118+
; PTX-DAG: setp.ge.u64 %p[[SRC_GT_THAN_DST:[0-9]+]], %rd{{[0-9]+}}, %rd{{[0-9]+}}
119119
; PTX-NEXT: @%p[[SRC_GT_THAN_DST]] bra LBB[[FORWARD_BB:[0-9_]+]]
120120
; -- this is the backwards copying BB
121121
; PTX: @%p[[NEQ0]] bra LBB[[EXIT:[0-9_]+]]

test/CodeGen/X86/and-sink.ll

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ define i32 @and_sink3(i1 %c, i32* %p) {
8080
; CHECK: testb $1,
8181
; CHECK: je
8282
; CHECK: movzbl
83-
; CHECK: movl $0, A
84-
; CHECK: testl %
83+
; CHECK-DAG: movl $0, A
84+
; CHECK-DAG: testl %
8585
; CHECK: je
8686

8787
; CHECK-CGP-LABEL: @and_sink3(
@@ -109,11 +109,11 @@ define i32 @and_sink4(i32 %a, i32 %b, i1 %c) {
109109
; CHECK: testb $1,
110110
; CHECK: je
111111
; CHECK-NOT: andl
112-
; CHECK: movl $0, A
113-
; CHECK: testl [[REG1:%[a-z0-9]+]], [[REG2:%[a-z0-9]+]]
112+
; CHECK-DAG: movl $0, A
113+
; CHECK-DAG: testl [[REG1:%[a-z0-9]+]], [[REG2:%[a-z0-9]+]]
114114
; CHECK: jne
115-
; CHECK: movl {{%[a-z0-9]+}}, B
116-
; CHECK: testl [[REG1]], [[REG2]]
115+
; CHECK-DAG: movl {{%[a-z0-9]+}}, B
116+
; CHECK-DAG: testl [[REG1]], [[REG2]]
117117
; CHECK: je
118118

119119
; CHECK-CGP-LABEL: @and_sink4(
@@ -148,11 +148,11 @@ define i32 @and_sink5(i32 %a, i32 %b, i32 %a2, i32 %b2, i1 %c) {
148148
; CHECK-LABEL: and_sink5:
149149
; CHECK: testb $1,
150150
; CHECK: je
151-
; CHECK: andl {{[0-9]+\(%[a-z0-9]+\)}}, [[REG:%[a-z0-9]+]]
152-
; CHECK: movl $0, A
151+
; CHECK-DAG: andl {{[0-9]+\(%[a-z0-9]+\)}}, [[REG:%[a-z0-9]+]]
152+
; CHECK-DAG: movl $0, A
153153
; CHECK: jne
154-
; CHECK: movl {{%[a-z0-9]+}}, B
155-
; CHECK: testl [[REG]], [[REG]]
154+
; CHECK-DAG: movl {{%[a-z0-9]+}}, B
155+
; CHECK-DAG: testl [[REG]], [[REG]]
156156
; CHECK: je
157157

158158
; CHECK-CGP-LABEL: @and_sink5(

test/CodeGen/X86/avx512-fsel.ll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ define i32 @test(float %a, float %b) {
1212
; CHECK-NEXT: .cfi_def_cfa_offset 16
1313
; CHECK-NEXT: movb $1, %al
1414
; CHECK-NEXT: vucomiss %xmm1, %xmm0
15-
; CHECK-NEXT: setnp %cl
16-
; CHECK-NEXT: sete %dl
17-
; CHECK-NEXT: setp %sil
18-
; CHECK-NEXT: setne %dil
19-
; CHECK-NEXT: andb %cl, %dl
15+
; CHECK-NEXT: setp %cl
16+
; CHECK-NEXT: setne %dl
17+
; CHECK-NEXT: setnp %sil
18+
; CHECK-NEXT: sete %dil
19+
; CHECK-NEXT: andb %sil, %dil
2020
; CHECK-NEXT: ## implicit-def: %R8D
21-
; CHECK-NEXT: movb %dl, %r8b
21+
; CHECK-NEXT: movb %dil, %r8b
2222
; CHECK-NEXT: andl $1, %r8d
2323
; CHECK-NEXT: kmovw %r8d, %k0
24-
; CHECK-NEXT: orb %sil, %dil
24+
; CHECK-NEXT: orb %cl, %dl
2525
; CHECK-NEXT: ## implicit-def: %R8D
26-
; CHECK-NEXT: movb %dil, %r8b
26+
; CHECK-NEXT: movb %dl, %r8b
2727
; CHECK-NEXT: andl $1, %r8d
2828
; CHECK-NEXT: kmovw %r8d, %k1
2929
; CHECK-NEXT: kmovw %k1, %ecx

test/CodeGen/X86/fp128-i128.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,10 @@ cleanup: ; preds = %entry, %if.then
306306
ret void
307307
; CHECK-LABEL: TestCopySign
308308
; CHECK-NOT: call
309-
; CHECK: callq __subtf3
310-
; CHECK-NOT: call
311309
; CHECK: callq __gttf2
312310
; CHECK-NOT: call
311+
; CHECK: callq __subtf3
312+
; CHECK-NOT: call
313313
; CHECK: andps {{.*}}, %xmm0
314314
; CHECK: retq
315315
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
; RUN: llc -stop-after=expand-isel-pseudos < %s | FileCheck %s
2+
;
3+
; Make sure that when the entry block of IR below is lowered, an instruction
4+
; that implictly defines %eflags has a same debug location with the icmp
5+
; instruction, and the branch instructions have a same debug location with the
6+
; br instruction.
7+
;
8+
; CHECK: [[DLOC1:![0-9]+]] = !DILocation(line: 5, column: 9, scope: !{{[0-9]+}})
9+
; CHECK: [[DLOC2:![0-9]+]] = !DILocation(line: 5, column: 7, scope: !{{[0-9]+}})
10+
; CHECK-DAG: [[VREG1:%[^ ]+]] = COPY %esi
11+
; CHECK-DAG: [[VREG2:%[^ ]+]] = COPY %edi
12+
; CHECK: SUB32rr [[VREG2]], [[VREG1]], implicit-def %eflags, debug-location [[DLOC1]]
13+
; CHECK-NEXT: JE_1{{.*}} implicit %eflags, debug-location [[DLOC2]]
14+
; CHECK-NEXT: JMP_1{{.*}} debug-location [[DLOC2]]
15+
16+
target triple = "x86_64-unknown-linux-gnu"
17+
18+
; Function Attrs: nounwind uwtable
19+
define i32 @foo(i32 %x, i32 %y) !dbg !4 {
20+
entry:
21+
tail call void @llvm.dbg.value(metadata i32 %x, i64 0, metadata !9, metadata !11), !dbg !12
22+
tail call void @llvm.dbg.value(metadata i32 %y, i64 0, metadata !10, metadata !11), !dbg !13
23+
%cmp = icmp ne i32 %x, %y, !dbg !14
24+
br i1 %cmp, label %if.then, label %if.else, !dbg !16
25+
26+
if.then: ; preds = %entry
27+
%call = tail call i32 (...) @bar() #3, !dbg !17
28+
br label %return, !dbg !18
29+
30+
if.else: ; preds = %entry
31+
%call1 = tail call i32 (...) @baz() #3, !dbg !19
32+
br label %return, !dbg !20
33+
34+
return: ; preds = %if.else, %if.then
35+
%retval.0 = phi i32 [ %call, %if.then ], [ %call1, %if.else ]
36+
ret i32 %retval.0, !dbg !21
37+
}
38+
39+
declare i32 @bar(...)
40+
declare i32 @baz(...)
41+
42+
; Function Attrs: nounwind readnone
43+
declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
44+
45+
!llvm.dbg.cu = !{!0}
46+
!llvm.module.flags = !{!2, !3}
47+
48+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, emissionKind: FullDebug)
49+
!1 = !DIFile(filename: "foo.c", directory: "b/")
50+
!2 = !{i32 2, !"Dwarf Version", i32 4}
51+
!3 = !{i32 2, !"Debug Info Version", i32 3}
52+
!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 4, type: !5, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !8)
53+
!5 = !DISubroutineType(types: !6)
54+
!6 = !{!7, !7, !7}
55+
!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
56+
!8 = !{!9, !10}
57+
!9 = !DILocalVariable(name: "x", arg: 1, scope: !4, file: !1, line: 4, type: !7)
58+
!10 = !DILocalVariable(name: "y", arg: 2, scope: !4, file: !1, line: 4, type: !7)
59+
!11 = !DIExpression()
60+
!12 = !DILocation(line: 4, column: 13, scope: !4)
61+
!13 = !DILocation(line: 4, column: 20, scope: !4)
62+
!14 = !DILocation(line: 5, column: 9, scope: !15)
63+
!15 = distinct !DILexicalBlock(scope: !4, file: !1, line: 5, column: 7)
64+
!16 = !DILocation(line: 5, column: 7, scope: !4)
65+
!17 = !DILocation(line: 6, column: 12, scope: !15)
66+
!18 = !DILocation(line: 6, column: 5, scope: !15)
67+
!19 = !DILocation(line: 8, column: 12, scope: !15)
68+
!20 = !DILocation(line: 8, column: 5, scope: !15)
69+
!21 = !DILocation(line: 9, column: 1, scope: !4)

0 commit comments

Comments
 (0)