2016-06-12 17:56:05 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
|
2018-04-12 00:03:07 +08:00
|
|
|
; RUN: llc -fast-isel-sink-local-values < %s -fast-isel -mtriple=i686-unknown-unknown -mattr=+bmi | FileCheck %s --check-prefix=X32
|
|
|
|
; RUN: llc -fast-isel-sink-local-values < %s -fast-isel -mtriple=x86_64-unknown-unknown -mattr=+bmi | FileCheck %s --check-prefix=X64
|
2016-06-12 17:56:05 +08:00
|
|
|
|
|
|
|
; NOTE: This should use IR equivalent to what is generated by clang/test/CodeGen/bmi-builtins.c
|
|
|
|
|
|
|
|
;
|
|
|
|
; AMD Intrinsics
|
|
|
|
;
|
|
|
|
|
|
|
|
define i16 @test__tzcnt_u16(i16 %a0) {
|
|
|
|
; X32-LABEL: test__tzcnt_u16:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movzwl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X32-NEXT: movzwl %ax, %ecx
|
|
|
|
; X32-NEXT: cmpl $0, %ecx
|
|
|
|
; X32-NEXT: jne .LBB0_1
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32-NEXT: # %bb.2:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movw $16, %ax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
; X32-NEXT: .LBB0_1:
|
|
|
|
; X32-NEXT: tzcntw %ax, %ax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
;
|
|
|
|
; X64-LABEL: test__tzcnt_u16:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0:
|
[FastISel] Sink local value materializations to first use
Summary:
Local values are constants, global addresses, and stack addresses that
can't be folded into the instruction that uses them. For example, when
storing the address of a global variable into memory, we need to
materialize that address into a register.
FastISel doesn't want to materialize any given local value more than
once, so it generates all local value materialization code at
EmitStartPt, which always dominates the current insertion point. This
allows it to maintain a map of local value registers, and it knows that
the local value area will always dominate the current insertion point.
The downside is that local value instructions are always emitted without
a source location. This is done to prevent jumpy line tables, but it
means that the local value area will be considered part of the previous
statement. Consider this C code:
call1(); // line 1
++global; // line 2
++global; // line 3
call2(&global, &local); // line 4
Today we end up with assembly and line tables like this:
.loc 1 1
callq call1
leaq global(%rip), %rdi
leaq local(%rsp), %rsi
.loc 1 2
addq $1, global(%rip)
.loc 1 3
addq $1, global(%rip)
.loc 1 4
callq call2
The LEA instructions in the local value area have no source location and
are treated as being on line 1. Stepping through the code in a debugger
and correlating it with the assembly won't make much sense, because
these materializations are only required for line 4.
This is actually problematic for the VS debugger "set next statement"
feature, which effectively assumes that there are no registers live
across statement boundaries. By sinking the local value code into the
statement and fixing up the source location, we can make that feature
work. This was filed as https://bugs.llvm.org/show_bug.cgi?id=35975 and
https://crbug.com/793819.
This change is obviously not enough to make this feature work reliably
in all cases, but I felt that it was worth doing anyway because it
usually generates smaller, more comprehensible -O0 code. I measured a
0.12% regression in code generation time with LLC on the sqlite3
amalgamation, so I think this is worth doing.
There are some special cases worth calling out in the commit message:
1. local values materialized for phis
2. local values used by no-op casts
3. dead local value code
Local values can be materialized for phis, and this does not show up as
a vreg use in MachineRegisterInfo. In this case, if there are no other
uses, this patch sinks the value to the first terminator, EH label, or
the end of the BB if nothing else exists.
Local values may also be used by no-op casts, which adds the register to
the RegFixups table. Without reversing the RegFixups map direction, we
don't have enough information to sink these instructions.
Lastly, if the local value register has no other uses, we can delete it.
This comes up when fastisel tries two instruction selection approaches
and the first materializes the value but fails and the second succeeds
without using the local value.
Reviewers: aprantl, dblaikie, qcolombet, MatzeB, vsk, echristo
Subscribers: dotdash, chandlerc, hans, sdardis, amccarth, javed.absar, zturner, llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D43093
llvm-svn: 327581
2018-03-15 05:54:21 +08:00
|
|
|
; X64-NEXT: movzwl %di, %eax
|
|
|
|
; X64-NEXT: tzcntw %ax, %cx
|
|
|
|
; X64-NEXT: cmpl $0, %eax
|
|
|
|
; X64-NEXT: movw $16, %ax
|
|
|
|
; X64-NEXT: cmovnew %cx, %ax
|
2016-06-12 17:56:05 +08:00
|
|
|
; X64-NEXT: retq
|
|
|
|
%zext = zext i16 %a0 to i32
|
|
|
|
%cmp = icmp ne i32 %zext, 0
|
|
|
|
%cttz = call i16 @llvm.cttz.i16(i16 %a0, i1 true)
|
|
|
|
%res = select i1 %cmp, i16 %cttz, i16 16
|
|
|
|
ret i16 %res
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test__andn_u32(i32 %a0, i32 %a1) {
|
|
|
|
; X32-LABEL: test__andn_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X32-NEXT: xorl $-1, %eax
|
|
|
|
; X32-NEXT: andl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
;
|
|
|
|
; X64-LABEL: test__andn_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X64-NEXT: xorl $-1, %edi
|
|
|
|
; X64-NEXT: andl %esi, %edi
|
|
|
|
; X64-NEXT: movl %edi, %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
%xor = xor i32 %a0, -1
|
|
|
|
%res = and i32 %xor, %a1
|
|
|
|
ret i32 %res
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test__bextr_u32(i32 %a0, i32 %a1) {
|
|
|
|
; X32-LABEL: test__bextr_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X32-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
;
|
|
|
|
; X64-LABEL: test__bextr_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X64-NEXT: bextrl %esi, %edi, %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
%res = call i32 @llvm.x86.bmi.bextr.32(i32 %a0, i32 %a1)
|
|
|
|
ret i32 %res
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test__blsi_u32(i32 %a0) {
|
|
|
|
; X32-LABEL: test__blsi_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; X32-NEXT: xorl %eax, %eax
|
|
|
|
; X32-NEXT: subl %ecx, %eax
|
|
|
|
; X32-NEXT: andl %ecx, %eax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
;
|
|
|
|
; X64-LABEL: test__blsi_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X64-NEXT: xorl %eax, %eax
|
|
|
|
; X64-NEXT: subl %edi, %eax
|
|
|
|
; X64-NEXT: andl %edi, %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
%neg = sub i32 0, %a0
|
|
|
|
%res = and i32 %a0, %neg
|
|
|
|
ret i32 %res
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test__blsmsk_u32(i32 %a0) {
|
|
|
|
; X32-LABEL: test__blsmsk_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; X32-NEXT: movl %ecx, %eax
|
|
|
|
; X32-NEXT: subl $1, %eax
|
|
|
|
; X32-NEXT: xorl %ecx, %eax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
;
|
|
|
|
; X64-LABEL: test__blsmsk_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X64-NEXT: movl %edi, %eax
|
|
|
|
; X64-NEXT: subl $1, %eax
|
|
|
|
; X64-NEXT: xorl %edi, %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
%dec = sub i32 %a0, 1
|
|
|
|
%res = xor i32 %a0, %dec
|
|
|
|
ret i32 %res
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test__blsr_u32(i32 %a0) {
|
|
|
|
; X32-LABEL: test__blsr_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; X32-NEXT: movl %ecx, %eax
|
|
|
|
; X32-NEXT: subl $1, %eax
|
|
|
|
; X32-NEXT: andl %ecx, %eax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
;
|
|
|
|
; X64-LABEL: test__blsr_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X64-NEXT: movl %edi, %eax
|
|
|
|
; X64-NEXT: subl $1, %eax
|
|
|
|
; X64-NEXT: andl %edi, %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
%dec = sub i32 %a0, 1
|
|
|
|
%res = and i32 %a0, %dec
|
|
|
|
ret i32 %res
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test__tzcnt_u32(i32 %a0) {
|
|
|
|
; X32-LABEL: test__tzcnt_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X32-NEXT: cmpl $0, %eax
|
|
|
|
; X32-NEXT: jne .LBB6_1
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32-NEXT: # %bb.2:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movl $32, %eax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
; X32-NEXT: .LBB6_1:
|
|
|
|
; X32-NEXT: tzcntl %eax, %eax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
;
|
|
|
|
; X64-LABEL: test__tzcnt_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0:
|
[FastISel] Sink local value materializations to first use
Summary:
Local values are constants, global addresses, and stack addresses that
can't be folded into the instruction that uses them. For example, when
storing the address of a global variable into memory, we need to
materialize that address into a register.
FastISel doesn't want to materialize any given local value more than
once, so it generates all local value materialization code at
EmitStartPt, which always dominates the current insertion point. This
allows it to maintain a map of local value registers, and it knows that
the local value area will always dominate the current insertion point.
The downside is that local value instructions are always emitted without
a source location. This is done to prevent jumpy line tables, but it
means that the local value area will be considered part of the previous
statement. Consider this C code:
call1(); // line 1
++global; // line 2
++global; // line 3
call2(&global, &local); // line 4
Today we end up with assembly and line tables like this:
.loc 1 1
callq call1
leaq global(%rip), %rdi
leaq local(%rsp), %rsi
.loc 1 2
addq $1, global(%rip)
.loc 1 3
addq $1, global(%rip)
.loc 1 4
callq call2
The LEA instructions in the local value area have no source location and
are treated as being on line 1. Stepping through the code in a debugger
and correlating it with the assembly won't make much sense, because
these materializations are only required for line 4.
This is actually problematic for the VS debugger "set next statement"
feature, which effectively assumes that there are no registers live
across statement boundaries. By sinking the local value code into the
statement and fixing up the source location, we can make that feature
work. This was filed as https://bugs.llvm.org/show_bug.cgi?id=35975 and
https://crbug.com/793819.
This change is obviously not enough to make this feature work reliably
in all cases, but I felt that it was worth doing anyway because it
usually generates smaller, more comprehensible -O0 code. I measured a
0.12% regression in code generation time with LLC on the sqlite3
amalgamation, so I think this is worth doing.
There are some special cases worth calling out in the commit message:
1. local values materialized for phis
2. local values used by no-op casts
3. dead local value code
Local values can be materialized for phis, and this does not show up as
a vreg use in MachineRegisterInfo. In this case, if there are no other
uses, this patch sinks the value to the first terminator, EH label, or
the end of the BB if nothing else exists.
Local values may also be used by no-op casts, which adds the register to
the RegFixups table. Without reversing the RegFixups map direction, we
don't have enough information to sink these instructions.
Lastly, if the local value register has no other uses, we can delete it.
This comes up when fastisel tries two instruction selection approaches
and the first materializes the value but fails and the second succeeds
without using the local value.
Reviewers: aprantl, dblaikie, qcolombet, MatzeB, vsk, echristo
Subscribers: dotdash, chandlerc, hans, sdardis, amccarth, javed.absar, zturner, llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D43093
llvm-svn: 327581
2018-03-15 05:54:21 +08:00
|
|
|
; X64-NEXT: tzcntl %edi, %ecx
|
|
|
|
; X64-NEXT: movl $32, %eax
|
|
|
|
; X64-NEXT: cmovael %ecx, %eax
|
2016-06-12 17:56:05 +08:00
|
|
|
; X64-NEXT: retq
|
|
|
|
%cmp = icmp ne i32 %a0, 0
|
|
|
|
%cttz = call i32 @llvm.cttz.i32(i32 %a0, i1 true)
|
|
|
|
%res = select i1 %cmp, i32 %cttz, i32 32
|
|
|
|
ret i32 %res
|
|
|
|
}
|
|
|
|
|
|
|
|
;
|
|
|
|
; Intel intrinsics
|
|
|
|
;
|
|
|
|
|
|
|
|
define i16 @test_tzcnt_u16(i16 %a0) {
|
|
|
|
; X32-LABEL: test_tzcnt_u16:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movzwl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X32-NEXT: movzwl %ax, %ecx
|
|
|
|
; X32-NEXT: cmpl $0, %ecx
|
|
|
|
; X32-NEXT: jne .LBB7_1
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32-NEXT: # %bb.2:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movw $16, %ax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
; X32-NEXT: .LBB7_1:
|
|
|
|
; X32-NEXT: tzcntw %ax, %ax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
;
|
|
|
|
; X64-LABEL: test_tzcnt_u16:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0:
|
[FastISel] Sink local value materializations to first use
Summary:
Local values are constants, global addresses, and stack addresses that
can't be folded into the instruction that uses them. For example, when
storing the address of a global variable into memory, we need to
materialize that address into a register.
FastISel doesn't want to materialize any given local value more than
once, so it generates all local value materialization code at
EmitStartPt, which always dominates the current insertion point. This
allows it to maintain a map of local value registers, and it knows that
the local value area will always dominate the current insertion point.
The downside is that local value instructions are always emitted without
a source location. This is done to prevent jumpy line tables, but it
means that the local value area will be considered part of the previous
statement. Consider this C code:
call1(); // line 1
++global; // line 2
++global; // line 3
call2(&global, &local); // line 4
Today we end up with assembly and line tables like this:
.loc 1 1
callq call1
leaq global(%rip), %rdi
leaq local(%rsp), %rsi
.loc 1 2
addq $1, global(%rip)
.loc 1 3
addq $1, global(%rip)
.loc 1 4
callq call2
The LEA instructions in the local value area have no source location and
are treated as being on line 1. Stepping through the code in a debugger
and correlating it with the assembly won't make much sense, because
these materializations are only required for line 4.
This is actually problematic for the VS debugger "set next statement"
feature, which effectively assumes that there are no registers live
across statement boundaries. By sinking the local value code into the
statement and fixing up the source location, we can make that feature
work. This was filed as https://bugs.llvm.org/show_bug.cgi?id=35975 and
https://crbug.com/793819.
This change is obviously not enough to make this feature work reliably
in all cases, but I felt that it was worth doing anyway because it
usually generates smaller, more comprehensible -O0 code. I measured a
0.12% regression in code generation time with LLC on the sqlite3
amalgamation, so I think this is worth doing.
There are some special cases worth calling out in the commit message:
1. local values materialized for phis
2. local values used by no-op casts
3. dead local value code
Local values can be materialized for phis, and this does not show up as
a vreg use in MachineRegisterInfo. In this case, if there are no other
uses, this patch sinks the value to the first terminator, EH label, or
the end of the BB if nothing else exists.
Local values may also be used by no-op casts, which adds the register to
the RegFixups table. Without reversing the RegFixups map direction, we
don't have enough information to sink these instructions.
Lastly, if the local value register has no other uses, we can delete it.
This comes up when fastisel tries two instruction selection approaches
and the first materializes the value but fails and the second succeeds
without using the local value.
Reviewers: aprantl, dblaikie, qcolombet, MatzeB, vsk, echristo
Subscribers: dotdash, chandlerc, hans, sdardis, amccarth, javed.absar, zturner, llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D43093
llvm-svn: 327581
2018-03-15 05:54:21 +08:00
|
|
|
; X64-NEXT: movzwl %di, %eax
|
|
|
|
; X64-NEXT: tzcntw %ax, %cx
|
|
|
|
; X64-NEXT: cmpl $0, %eax
|
|
|
|
; X64-NEXT: movw $16, %ax
|
|
|
|
; X64-NEXT: cmovnew %cx, %ax
|
2016-06-12 17:56:05 +08:00
|
|
|
; X64-NEXT: retq
|
|
|
|
%zext = zext i16 %a0 to i32
|
|
|
|
%cmp = icmp ne i32 %zext, 0
|
|
|
|
%cttz = call i16 @llvm.cttz.i16(i16 %a0, i1 true)
|
|
|
|
%res = select i1 %cmp, i16 %cttz, i16 16
|
|
|
|
ret i16 %res
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test_andn_u32(i32 %a0, i32 %a1) {
|
|
|
|
; X32-LABEL: test_andn_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X32-NEXT: xorl $-1, %eax
|
|
|
|
; X32-NEXT: andl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
;
|
|
|
|
; X64-LABEL: test_andn_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X64-NEXT: xorl $-1, %edi
|
|
|
|
; X64-NEXT: andl %esi, %edi
|
|
|
|
; X64-NEXT: movl %edi, %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
%xor = xor i32 %a0, -1
|
|
|
|
%res = and i32 %xor, %a1
|
|
|
|
ret i32 %res
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test_bextr_u32(i32 %a0, i32 %a1, i32 %a2) {
|
|
|
|
; X32-LABEL: test_bextr_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; X32-NEXT: andl $255, %ecx
|
|
|
|
; X32-NEXT: andl $255, %eax
|
|
|
|
; X32-NEXT: shll $8, %eax
|
|
|
|
; X32-NEXT: orl %ecx, %eax
|
|
|
|
; X32-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
;
|
|
|
|
; X64-LABEL: test_bextr_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X64-NEXT: andl $255, %esi
|
|
|
|
; X64-NEXT: andl $255, %edx
|
|
|
|
; X64-NEXT: shll $8, %edx
|
|
|
|
; X64-NEXT: orl %esi, %edx
|
|
|
|
; X64-NEXT: bextrl %edx, %edi, %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
%and1 = and i32 %a1, 255
|
|
|
|
%and2 = and i32 %a2, 255
|
|
|
|
%shl = shl i32 %and2, 8
|
|
|
|
%or = or i32 %and1, %shl
|
|
|
|
%res = call i32 @llvm.x86.bmi.bextr.32(i32 %a0, i32 %or)
|
|
|
|
ret i32 %res
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test_blsi_u32(i32 %a0) {
|
|
|
|
; X32-LABEL: test_blsi_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; X32-NEXT: xorl %eax, %eax
|
|
|
|
; X32-NEXT: subl %ecx, %eax
|
|
|
|
; X32-NEXT: andl %ecx, %eax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
;
|
|
|
|
; X64-LABEL: test_blsi_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X64-NEXT: xorl %eax, %eax
|
|
|
|
; X64-NEXT: subl %edi, %eax
|
|
|
|
; X64-NEXT: andl %edi, %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
%neg = sub i32 0, %a0
|
|
|
|
%res = and i32 %a0, %neg
|
|
|
|
ret i32 %res
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test_blsmsk_u32(i32 %a0) {
|
|
|
|
; X32-LABEL: test_blsmsk_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; X32-NEXT: movl %ecx, %eax
|
|
|
|
; X32-NEXT: subl $1, %eax
|
|
|
|
; X32-NEXT: xorl %ecx, %eax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
;
|
|
|
|
; X64-LABEL: test_blsmsk_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X64-NEXT: movl %edi, %eax
|
|
|
|
; X64-NEXT: subl $1, %eax
|
|
|
|
; X64-NEXT: xorl %edi, %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
%dec = sub i32 %a0, 1
|
|
|
|
%res = xor i32 %a0, %dec
|
|
|
|
ret i32 %res
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test_blsr_u32(i32 %a0) {
|
|
|
|
; X32-LABEL: test_blsr_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; X32-NEXT: movl %ecx, %eax
|
|
|
|
; X32-NEXT: subl $1, %eax
|
|
|
|
; X32-NEXT: andl %ecx, %eax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
;
|
|
|
|
; X64-LABEL: test_blsr_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X64-NEXT: movl %edi, %eax
|
|
|
|
; X64-NEXT: subl $1, %eax
|
|
|
|
; X64-NEXT: andl %edi, %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
%dec = sub i32 %a0, 1
|
|
|
|
%res = and i32 %a0, %dec
|
|
|
|
ret i32 %res
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test_tzcnt_u32(i32 %a0) {
|
|
|
|
; X32-LABEL: test_tzcnt_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32: # %bb.0:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X32-NEXT: cmpl $0, %eax
|
|
|
|
; X32-NEXT: jne .LBB13_1
|
2017-12-05 01:18:51 +08:00
|
|
|
; X32-NEXT: # %bb.2:
|
2016-06-12 17:56:05 +08:00
|
|
|
; X32-NEXT: movl $32, %eax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
; X32-NEXT: .LBB13_1:
|
|
|
|
; X32-NEXT: tzcntl %eax, %eax
|
|
|
|
; X32-NEXT: retl
|
|
|
|
;
|
|
|
|
; X64-LABEL: test_tzcnt_u32:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0:
|
[FastISel] Sink local value materializations to first use
Summary:
Local values are constants, global addresses, and stack addresses that
can't be folded into the instruction that uses them. For example, when
storing the address of a global variable into memory, we need to
materialize that address into a register.
FastISel doesn't want to materialize any given local value more than
once, so it generates all local value materialization code at
EmitStartPt, which always dominates the current insertion point. This
allows it to maintain a map of local value registers, and it knows that
the local value area will always dominate the current insertion point.
The downside is that local value instructions are always emitted without
a source location. This is done to prevent jumpy line tables, but it
means that the local value area will be considered part of the previous
statement. Consider this C code:
call1(); // line 1
++global; // line 2
++global; // line 3
call2(&global, &local); // line 4
Today we end up with assembly and line tables like this:
.loc 1 1
callq call1
leaq global(%rip), %rdi
leaq local(%rsp), %rsi
.loc 1 2
addq $1, global(%rip)
.loc 1 3
addq $1, global(%rip)
.loc 1 4
callq call2
The LEA instructions in the local value area have no source location and
are treated as being on line 1. Stepping through the code in a debugger
and correlating it with the assembly won't make much sense, because
these materializations are only required for line 4.
This is actually problematic for the VS debugger "set next statement"
feature, which effectively assumes that there are no registers live
across statement boundaries. By sinking the local value code into the
statement and fixing up the source location, we can make that feature
work. This was filed as https://bugs.llvm.org/show_bug.cgi?id=35975 and
https://crbug.com/793819.
This change is obviously not enough to make this feature work reliably
in all cases, but I felt that it was worth doing anyway because it
usually generates smaller, more comprehensible -O0 code. I measured a
0.12% regression in code generation time with LLC on the sqlite3
amalgamation, so I think this is worth doing.
There are some special cases worth calling out in the commit message:
1. local values materialized for phis
2. local values used by no-op casts
3. dead local value code
Local values can be materialized for phis, and this does not show up as
a vreg use in MachineRegisterInfo. In this case, if there are no other
uses, this patch sinks the value to the first terminator, EH label, or
the end of the BB if nothing else exists.
Local values may also be used by no-op casts, which adds the register to
the RegFixups table. Without reversing the RegFixups map direction, we
don't have enough information to sink these instructions.
Lastly, if the local value register has no other uses, we can delete it.
This comes up when fastisel tries two instruction selection approaches
and the first materializes the value but fails and the second succeeds
without using the local value.
Reviewers: aprantl, dblaikie, qcolombet, MatzeB, vsk, echristo
Subscribers: dotdash, chandlerc, hans, sdardis, amccarth, javed.absar, zturner, llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D43093
llvm-svn: 327581
2018-03-15 05:54:21 +08:00
|
|
|
; X64-NEXT: tzcntl %edi, %ecx
|
|
|
|
; X64-NEXT: movl $32, %eax
|
|
|
|
; X64-NEXT: cmovael %ecx, %eax
|
2016-06-12 17:56:05 +08:00
|
|
|
; X64-NEXT: retq
|
|
|
|
%cmp = icmp ne i32 %a0, 0
|
|
|
|
%cttz = call i32 @llvm.cttz.i32(i32 %a0, i1 true)
|
|
|
|
%res = select i1 %cmp, i32 %cttz, i32 32
|
|
|
|
ret i32 %res
|
|
|
|
}
|
|
|
|
|
|
|
|
declare i16 @llvm.cttz.i16(i16, i1)
|
|
|
|
declare i32 @llvm.cttz.i32(i32, i1)
|
|
|
|
declare i32 @llvm.x86.bmi.bextr.32(i32, i32)
|