xref: /llvm-project/llvm/test/DebugInfo/MIR/InstrRef/x86-lea-fixup.mir (revision 92b33822e989884d29465d34769b07d78aeb1a84)
1# RUN: llc -run-pass x86-fixup-LEAs -mtriple=x86_64-gnu-unknown -verify-machineinstrs -mcpu=corei7-avx -o - %s | FileCheck %s --check-prefixes=COREI7,CHECK
2# RUN: llc -run-pass x86-fixup-LEAs -mtriple=x86_64-gnu-unknown -verify-machineinstrs -mcpu=haswell -o - %s | FileCheck %s --check-prefixes=HASWELL,CHECK
3# RUN: llc -run-pass x86-fixup-LEAs -mtriple=x86_64-unknown-unknown -verify-machineinstrs -mcpu=atom -o - %s | FileCheck %s --check-prefixes=ATOM,CHECK
4#
5# Test several LEA <=> ADD transformations that the fixup-leas pass performs,
6# and check that any debug-instr-number attached to the original instruction
7# is substituted onto the new instruction.
8# Some are only reachable under specific CPU modes it seems -- each function
9# in this file is only tested by one prefix / CPU mode. Some i386 specific
10# behaviours are in the -2 flavour of this file.
11---
12# COREI7-LABEL: name: pr43758
13name:            pr43758
14alignment:       16
15tracksRegLiveness: true
16debugInstrRef: true
17liveins:
18  - { reg: '$rax' }
19  - { reg: '$rbp' }
20# COREI7:      debugValueSubstitutions:
21# COREI7-NEXT: - { srcinst: 1, srcop: 0, dstinst: 2, dstop: 0, subreg: 0 }
22body:             |
23  bb.0:
24    liveins: $rax, $rbp
25
26    $ebp = LEA64_32r killed $rbp, 1, killed $rax, 0, $noreg, debug-instr-number 1
27    ; COREI7: ADD32rr {{.*}} debug-instr-number 2
28    RET64 $ebp
29
30...
31---
32name:            test_mul_spec
33# HASWELL-LABEL: name: test_mul_spec
34alignment:       16
35tracksRegLiveness: true
36debugInstrRef: true
37liveins:
38  - { reg: '$edi' }
39frameInfo:
40  maxAlignment:    1
41  maxCallFrameSize: 0
42machineFunctionInfo: {}
43# HASWELL:      debugValueSubstitutions:
44# HASWELL-NEXT:  - { srcinst: 1, srcop: 0, dstinst: 3, dstop: 0, subreg: 0 }
45# HASWELL-NEXT:  - { srcinst: 2, srcop: 0, dstinst: 4, dstop: 0, subreg: 0 }
46body:             |
47  bb.0:
48    liveins: $edi
49
50    renamable $edi = KILL $edi, implicit-def $rdi
51    renamable $ecx = nsw LEA64_32r renamable $rdi, 8, renamable $rdi, 42, $noreg, debug-instr-number 1
52    ; HASWELL: ADD32ri {{.*}} debug-instr-number 3
53    renamable $eax = nsw LEA64_32r killed renamable $rdi, 4, renamable $rdi, 2, $noreg, debug-instr-number 2
54    ; HASWELL: ADD32ri {{.*}} debug-instr-number 4
55    renamable $eax = nsw IMUL32rr killed renamable $eax, killed renamable $ecx, implicit-def dead $eflags
56    RET64 $eax
57
58...
59---
60name:            testthree
61# ATOM-LABEL: name: testthree
62alignment:       16
63tracksRegLiveness: true
64debugInstrRef: true
65frameInfo:
66  maxAlignment:    1
67  maxCallFrameSize: 0
68machineFunctionInfo: {}
69# ATOM:       debugValueSubstitutions:
70# ATOM-NEXT:  - { srcinst: 1, srcop: 0, dstinst: 2, dstop: 0, subreg: 0 }
71body:             |
72  bb.0.entry:
73    renamable $ecx = MOV32ri 0
74    renamable $eax = XOR32rr undef $eax, undef $eax, implicit-def dead $eflags
75    renamable $ecx = nsw ADD32rr renamable $ecx, renamable $eax, implicit-def dead $eflags, implicit killed $rax, implicit killed $rcx, implicit-def $rcx, debug-instr-number 1
76    ; ATOM: LEA64_32r {{.*}} debug-instr-number 2
77    renamable $eax = MOV32rm killed renamable $rcx, 1, $noreg, 0, $noreg :: (load (s32) from `ptr undef`)
78    RET64 $eax
79
80...
81---
82# CHECK-LABEL: testfour
83# In this code sequence, an LEA is converted into a subtract that's combined
84# with another subtract. The instruction number on the computed value should
85# only be attached to the last subtract.
86name:            testfour
87alignment:       16
88tracksRegLiveness: true
89tracksDebugUserValues: true
90debugInstrRef: true
91liveins:
92  - { reg: '$esi' }
93frameInfo:
94  maxAlignment:    1
95  maxCallFrameSize: 0
96machineFunctionInfo: {}
97# CHECK:      debugValueSubstitutions:
98# CHECK-NEXT:  - { srcinst: 1, srcop: 0, dstinst: 2, dstop: 0, subreg: 0 }
99# CHECK-NEXT: constants:
100body:             |
101  bb.0.entry:
102    liveins: $esi
103
104    $eax = MOV32rr $esi, implicit-def $rax
105
106    renamable $ecx = LEA64_32r renamable $rax, 1, renamable $rax, 0, $noreg
107    renamable $edx = MOV32ri 1
108    renamable $edx = SUB32rr killed renamable $edx, killed renamable $ecx, implicit-def dead $eflags, debug-instr-number 1
109
110    ; CHECK:      MOV32ri 1
111    ; CHECK-NOT:  debug-instr-number
112    ; CHECK-NEXT: SUB32rr
113    ; CHECK-NOT:  debug-instr-number
114    ; CHECK-NEXT: SUB32rr
115    ; CHECK-SAME: debug-instr-number 2
116
117    MOV32mr $noreg, 1, $noreg, 0, $noreg, killed renamable $edx
118    $eax = KILL renamable $eax, implicit killed $rax
119    RET64 $eax
120
121...
122