Skip to content

Commit 0968eed

Browse files
committed
[LLVM,X64] Avoid icmp zext where possible
We can't use xor and mov reg, 0 is a 5/6-byte instruction.
1 parent 1486243 commit 0968eed

File tree

8 files changed

+11
-113
lines changed

8 files changed

+11
-113
lines changed

tpde-llvm/src/x64/LLVMCompilerX64.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ bool LLVMCompilerX64::compile_icmp(const llvm::Instruction *inst,
422422
if (fuse_br) {
423423
if (!single_use) {
424424
(void)result_ref(cmp); // ref-count for branch
425-
generate_raw_set(jump, result_ref(cmp).part(0).alloc_reg());
425+
generate_raw_set(
426+
jump, result_ref(cmp).part(0).alloc_reg(), /*zext=*/false);
426427
}
427428
auto true_block = adaptor->block_lookup_idx(fuse_br->getSuccessor(0));
428429
auto false_block = adaptor->block_lookup_idx(fuse_br->getSuccessor(1));
@@ -431,14 +432,14 @@ bool LLVMCompilerX64::compile_icmp(const llvm::Instruction *inst,
431432
} else if (fuse_ext) {
432433
auto [_, res_ref] = result_ref_single(fuse_ext);
433434
if (llvm::isa<llvm::ZExtInst>(fuse_ext)) {
434-
generate_raw_set(jump, res_ref.alloc_reg());
435+
generate_raw_set(jump, res_ref.alloc_reg(), /*zext=*/true);
435436
} else {
436437
generate_raw_mask(jump, res_ref.alloc_reg());
437438
}
438439
this->adaptor->inst_set_fused(fuse_ext, true);
439440
} else {
440441
auto [_, res_ref] = result_ref_single(cmp);
441-
generate_raw_set(jump, res_ref.alloc_reg());
442+
generate_raw_set(jump, res_ref.alloc_reg(), /*zext=*/false);
442443
}
443444

444445
return true;

tpde-llvm/test/filetest/alloca.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,14 +1260,12 @@ define void @alloca_manyregs(i32 %0, ptr %1, ptr %2, ptr %3, i64 %4, i32 %5, ptr
12601260
; X64-NEXT: mov r12, r11
12611261
; X64-NEXT: mov r12, qword ptr [rbp - 0x40820]
12621262
; X64-NEXT: test r12, r12
1263-
; X64-NEXT: mov r13d, 0x0
12641263
; X64-NEXT: sete r13b
12651264
; X64-NEXT: mov r13d, dword ptr [rbp - 0x407f8]
12661265
; X64-NEXT: mov r14d, r13d
12671266
; X64-NEXT: and r14d, 0x0
12681267
; X64-NEXT: mov r14, qword ptr [rbp - 0x38]
12691268
; X64-NEXT: test r14, r14
1270-
; X64-NEXT: mov r15d, 0x0
12711269
; X64-NEXT: sete r15b
12721270
; X64-NEXT: mov r15, qword ptr [rbp - 0x40]
12731271
; X64-NEXT: mov eax, dword ptr [r15]
@@ -1281,7 +1279,6 @@ define void @alloca_manyregs(i32 %0, ptr %1, ptr %2, ptr %3, i64 %4, i32 %5, ptr
12811279
; X64-NEXT: mov dword ptr [0x0], ecx
12821280
; X64-NEXT: mov rcx, qword ptr [rbp - 0x60]
12831281
; X64-NEXT: test rcx, rcx
1284-
; X64-NEXT: mov ecx, 0x0
12851282
; X64-NEXT: sete cl
12861283
; X64-NEXT: mov rcx, qword ptr [rbp - 0x407d8]
12871284
; X64-NEXT: lea rdx, [rcx + 0x4]

tpde-llvm/test/filetest/constants.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,6 @@ define void @phi_gep_before_icmp_twice() {
14211421
; X64-NEXT: lea rcx, [rcx + 0xa]
14221422
; X64-NEXT: mov edx, 0x0
14231423
; X64-NEXT: test rdx, rdx
1424-
; X64-NEXT: mov edx, 0x0
14251424
; X64-NEXT: setl dl
14261425
; X64-NEXT: mov edx, 0x0
14271426
; X64-NEXT: test dl, 0x1

tpde-llvm/test/filetest/icmp-fuse-ext.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ define i128 @icmp_fuse_zexti128(i32, i32) {
9696
; X64-NEXT: nop word ptr [rax + rax]
9797
; X64-NEXT: sub rsp, 0x30
9898
; X64-NEXT: cmp edi, esi
99-
; X64-NEXT: mov eax, 0x0
10099
; X64-NEXT: setl al
101100
; X64-NEXT: and eax, 0x1
102101
; X64-NEXT: mov ecx, 0x0
@@ -245,7 +244,6 @@ define i128 @icmp_fuse_sexti128(i32, i32) {
245244
; X64-NEXT: nop word ptr [rax + rax]
246245
; X64-NEXT: sub rsp, 0x30
247246
; X64-NEXT: cmp edi, esi
248-
; X64-NEXT: mov eax, 0x0
249247
; X64-NEXT: setl al
250248
; X64-NEXT: shl rax, 0x3f
251249
; X64-NEXT: sar rax, 0x3f
@@ -280,7 +278,6 @@ define i64 @icmp_ext_nofuse(i32, i32) {
280278
; X64-NEXT: nop word ptr [rax + rax]
281279
; X64-NEXT: sub rsp, 0x30
282280
; X64-NEXT: cmp edi, esi
283-
; X64-NEXT: mov eax, 0x0
284281
; X64-NEXT: setl al
285282
; X64-NEXT: mov ecx, eax
286283
; X64-NEXT: and ecx, 0x1

0 commit comments

Comments
 (0)