Sergei Barannikov 5080a0251f
[CodeGenPrepare] Unfold slow ctpop when used in power-of-two test (#102731)
DAG combiner already does this transformation, but in some cases it does
not have a chance because either CodeGenPrepare or SelectionDAGBuilder
move icmp to a different basic block.

https://alive2.llvm.org/ce/z/ARzh99

Fixes #94829

Pull Request: https://github.com/llvm/llvm-project/pull/102731
2025-04-23 08:54:10 +03:00

33 lines
920 B
LLVM

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc --mtriple=x86_64 -o - %s | FileCheck %s
define i64 @test(i64 %x, i64 %y, i64 %a, i64 %b) {
; CHECK-LABEL: test:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: testq %rsi, %rsi
; CHECK-NEXT: jg .LBB0_2
; CHECK-NEXT: # %bb.1: # %entry
; CHECK-NEXT: movq %rcx, %rax
; CHECK-NEXT: leaq -1(%rdi), %rcx
; CHECK-NEXT: andq %rdi, %rcx
; CHECK-NEXT: jne .LBB0_2
; CHECK-NEXT: # %bb.3: # %if.end
; CHECK-NEXT: retq
; CHECK-NEXT: .LBB0_2: # %if.then
; CHECK-NEXT: movq %rdx, %rax
; CHECK-NEXT: retq
entry:
%ctpop = call i64 @llvm.ctpop.i64(i64 %x)
%cmp1 = icmp ugt i64 %ctpop, 1
%cmp2 = icmp sgt i64 %y, 0
%cmp = or i1 %cmp2, %cmp1
br i1 %cmp, label %if.then, label %if.end
if.then:
br label %if.end
if.end:
%res = phi i64 [ %a, %if.then ], [ %b, %entry ]
ret i64 %res
}