Skip to content

Commit

Permalink
Revert "[X86] Promote cttz_i32(x) -> cttz_i64((i64)x | (1 << 32))" (l…
Browse files Browse the repository at this point in the history
…lvm#103030)

Reverts llvm#102900 - missed a analysis cost model test change
  • Loading branch information
RKSimon authored Aug 13, 2024
1 parent f9b15a9 commit 346a1c5
Show file tree
Hide file tree
Showing 5 changed files with 240 additions and 154 deletions.
6 changes: 2 additions & 4 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
setOperationAction(ISD::CTTZ , MVT::i32 , Custom);
setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i32 , Legal);
if (Subtarget.is64Bit()) {
setOperationPromotedToType(ISD::CTTZ , MVT::i32, MVT::i64);
setOperationAction(ISD::CTTZ , MVT::i64 , Custom);
setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i64, Legal);
}
Expand Down Expand Up @@ -3238,10 +3237,9 @@ bool X86TargetLowering::shouldFormOverflowOp(unsigned Opcode, EVT VT,
}

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

bool X86TargetLowering::isCheapToSpeculateCtlz(Type *Ty) const {
Expand Down
12 changes: 7 additions & 5 deletions llvm/test/CodeGen/X86/cttz.ll
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,13 @@ define i32 @cttz_i32_zero_test(i32 %n) {
;
; X64-LABEL: cttz_i32_zero_test:
; X64: # %bb.0:
; X64-NEXT: # kill: def $edi killed $edi def $rdi
; X64-NEXT: movabsq $4294967296, %rax # imm = 0x100000000
; X64-NEXT: orq %rdi, %rax
; X64-NEXT: rep bsfq %rax, %rax
; X64-NEXT: # kill: def $eax killed $eax killed $rax
; X64-NEXT: testl %edi, %edi
; X64-NEXT: je .LBB6_1
; X64-NEXT: # %bb.2: # %cond.false
; X64-NEXT: rep bsfl %edi, %eax
; X64-NEXT: retq
; X64-NEXT: .LBB6_1:
; X64-NEXT: movl $32, %eax
; X64-NEXT: retq
;
; X86-CLZ-LABEL: cttz_i32_zero_test:
Expand Down
Loading

0 comments on commit 346a1c5

Please sign in to comment.