Skip to content

Commit 78a28b3

Browse files
authored
[X86] Support icmp_i64(i64 X, i64 Y) --> icmp_i32(trunc(X), trunc(Y)) for non-constant Y (#91085)
Relax the constraint on the fold to allow any value for X and Y iff all upper 32-bits are known zero Minor code-size saving by moving to i32 bit instructions
1 parent 7d913c5 commit 78a28b3

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22708,10 +22708,10 @@ static SDValue EmitCmp(SDValue Op0, SDValue Op1, unsigned X86CC,
2270822708
}
2270922709

2271022710
// Try to shrink i64 compares if the input has enough zero bits.
22711-
// FIXME: Do this for non-constant compares for constant on LHS?
22712-
if (CmpVT == MVT::i64 && isa<ConstantSDNode>(Op1) && !isX86CCSigned(X86CC) &&
22711+
// TODO: Add sign-bits equivalent for isX86CCSigned(X86CC)?
22712+
if (CmpVT == MVT::i64 && !isX86CCSigned(X86CC) &&
2271322713
Op0.hasOneUse() && // Hacky way to not break CSE opportunities with sub.
22714-
Op1->getAsAPIntVal().getActiveBits() <= 32 &&
22714+
DAG.MaskedValueIsZero(Op1, APInt::getHighBitsSet(64, 32)) &&
2271522715
DAG.MaskedValueIsZero(Op0, APInt::getHighBitsSet(64, 32))) {
2271622716
CmpVT = MVT::i32;
2271722717
Op0 = DAG.getNode(ISD::TRUNCATE, dl, CmpVT, Op0);

llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ define i1 @shl_to_shr_eq_i64_s44(i64 %x) {
174174
; CHECK-NEXT: movq %rdi, %rax
175175
; CHECK-NEXT: shrq $44, %rax
176176
; CHECK-NEXT: andl $1048575, %edi # imm = 0xFFFFF
177-
; CHECK-NEXT: cmpq %rax, %rdi
177+
; CHECK-NEXT: cmpl %eax, %edi
178178
; CHECK-NEXT: sete %al
179179
; CHECK-NEXT: retq
180180
%shl = shl i64 %x, 44
@@ -186,9 +186,9 @@ define i1 @shl_to_shr_eq_i64_s44(i64 %x) {
186186
define i1 @shr_to_shl_ne_i64_s32(i64 %x) {
187187
; CHECK-NOBMI-LABEL: shr_to_shl_ne_i64_s32:
188188
; CHECK-NOBMI: # %bb.0:
189-
; CHECK-NOBMI-NEXT: movl %edi, %eax
190-
; CHECK-NOBMI-NEXT: shrq $32, %rdi
191-
; CHECK-NOBMI-NEXT: cmpq %rdi, %rax
189+
; CHECK-NOBMI-NEXT: movq %rdi, %rax
190+
; CHECK-NOBMI-NEXT: shrq $32, %rax
191+
; CHECK-NOBMI-NEXT: cmpl %eax, %edi
192192
; CHECK-NOBMI-NEXT: setne %al
193193
; CHECK-NOBMI-NEXT: retq
194194
;
@@ -244,7 +244,7 @@ define i1 @shl_to_shr_eq_i64_s63(i64 %x) {
244244
; CHECK-NEXT: movq %rdi, %rax
245245
; CHECK-NEXT: shrq $63, %rax
246246
; CHECK-NEXT: andl $1, %edi
247-
; CHECK-NEXT: cmpq %rax, %rdi
247+
; CHECK-NEXT: cmpl %eax, %edi
248248
; CHECK-NEXT: sete %al
249249
; CHECK-NEXT: retq
250250
%shl = shl i64 %x, 63

llvm/test/CodeGen/X86/vector-shift-by-select-loop.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ define void @vector_variable_shift_left_loop(ptr nocapture %arr, ptr nocapture r
115115
; SSE-NEXT: cmpq %rcx, %rdx
116116
; SSE-NEXT: jne .LBB0_4
117117
; SSE-NEXT: # %bb.5: # %middle.block
118-
; SSE-NEXT: cmpq %r9, %rdx
118+
; SSE-NEXT: cmpl %r9d, %edx
119119
; SSE-NEXT: jne .LBB0_6
120120
; SSE-NEXT: .LBB0_9: # %for.cond.cleanup
121121
; SSE-NEXT: retq
@@ -239,7 +239,7 @@ define void @vector_variable_shift_left_loop(ptr nocapture %arr, ptr nocapture r
239239
; AVX1-NEXT: cmpq %rcx, %rdx
240240
; AVX1-NEXT: jne .LBB0_4
241241
; AVX1-NEXT: # %bb.5: # %middle.block
242-
; AVX1-NEXT: cmpq %r9, %rdx
242+
; AVX1-NEXT: cmpl %r9d, %edx
243243
; AVX1-NEXT: jne .LBB0_6
244244
; AVX1-NEXT: .LBB0_9: # %for.cond.cleanup
245245
; AVX1-NEXT: vzeroupper
@@ -314,7 +314,7 @@ define void @vector_variable_shift_left_loop(ptr nocapture %arr, ptr nocapture r
314314
; AVX2-NEXT: cmpq %rcx, %rdx
315315
; AVX2-NEXT: jne .LBB0_4
316316
; AVX2-NEXT: # %bb.5: # %middle.block
317-
; AVX2-NEXT: cmpq %r9, %rdx
317+
; AVX2-NEXT: cmpl %r9d, %edx
318318
; AVX2-NEXT: jne .LBB0_6
319319
; AVX2-NEXT: .LBB0_9: # %for.cond.cleanup
320320
; AVX2-NEXT: vzeroupper
@@ -413,7 +413,7 @@ define void @vector_variable_shift_left_loop(ptr nocapture %arr, ptr nocapture r
413413
; XOP-NEXT: cmpq %rcx, %rdx
414414
; XOP-NEXT: jne .LBB0_4
415415
; XOP-NEXT: # %bb.5: # %middle.block
416-
; XOP-NEXT: cmpq %r9, %rdx
416+
; XOP-NEXT: cmpl %r9d, %edx
417417
; XOP-NEXT: jne .LBB0_6
418418
; XOP-NEXT: .LBB0_9: # %for.cond.cleanup
419419
; XOP-NEXT: vzeroupper

0 commit comments

Comments
 (0)