Skip to content

Commit 346a1c5

Browse files
authored
Revert "[X86] Promote cttz_i32(x) -> cttz_i64((i64)x | (1 << 32))" (#103030)
Reverts #102900 - missed a analysis cost model test change
1 parent f9b15a9 commit 346a1c5

File tree

5 files changed

+240
-154
lines changed

5 files changed

+240
-154
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
412412
setOperationAction(ISD::CTTZ , MVT::i32 , Custom);
413413
setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i32 , Legal);
414414
if (Subtarget.is64Bit()) {
415-
setOperationPromotedToType(ISD::CTTZ , MVT::i32, MVT::i64);
416415
setOperationAction(ISD::CTTZ , MVT::i64 , Custom);
417416
setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i64, Legal);
418417
}
@@ -3238,10 +3237,9 @@ bool X86TargetLowering::shouldFormOverflowOp(unsigned Opcode, EVT VT,
32383237
}
32393238

32403239
bool X86TargetLowering::isCheapToSpeculateCttz(Type *Ty) const {
3241-
// Speculate cttz only if we can directly use TZCNT or can promote to i32/i64.
3240+
// Speculate cttz only if we can directly use TZCNT or can promote to i32.
32423241
return Subtarget.hasBMI() ||
3243-
(!Ty->isVectorTy() &&
3244-
Ty->getScalarSizeInBits() < (Subtarget.is64Bit() ? 64u : 32u));
3242+
(!Ty->isVectorTy() && Ty->getScalarSizeInBits() < 32);
32453243
}
32463244

32473245
bool X86TargetLowering::isCheapToSpeculateCtlz(Type *Ty) const {

llvm/test/CodeGen/X86/cttz.ll

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,13 @@ define i32 @cttz_i32_zero_test(i32 %n) {
317317
;
318318
; X64-LABEL: cttz_i32_zero_test:
319319
; X64: # %bb.0:
320-
; X64-NEXT: # kill: def $edi killed $edi def $rdi
321-
; X64-NEXT: movabsq $4294967296, %rax # imm = 0x100000000
322-
; X64-NEXT: orq %rdi, %rax
323-
; X64-NEXT: rep bsfq %rax, %rax
324-
; X64-NEXT: # kill: def $eax killed $eax killed $rax
320+
; X64-NEXT: testl %edi, %edi
321+
; X64-NEXT: je .LBB6_1
322+
; X64-NEXT: # %bb.2: # %cond.false
323+
; X64-NEXT: rep bsfl %edi, %eax
324+
; X64-NEXT: retq
325+
; X64-NEXT: .LBB6_1:
326+
; X64-NEXT: movl $32, %eax
325327
; X64-NEXT: retq
326328
;
327329
; X86-CLZ-LABEL: cttz_i32_zero_test:

0 commit comments

Comments
 (0)