; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc --mtriple=riscv64 -o - %s | FileCheck %s

define i64 @test(i64 %x, ptr %p) {
; CHECK-LABEL: test:
; CHECK:       # %bb.0: # %entry
; CHECK-NEXT:    mv a2, a0
; CHECK-NEXT:    li a0, 0
; CHECK-NEXT:    bgtz a2, .LBB0_3
; CHECK-NEXT:  # %bb.1: # %entry
; CHECK-NEXT:    addi a3, a2, -1
; CHECK-NEXT:    and a2, a2, a3
; CHECK-NEXT:    bnez a2, .LBB0_3
; CHECK-NEXT:  # %bb.2: # %if.else
; CHECK-NEXT:    ld a0, 0(a1)
; CHECK-NEXT:  .LBB0_3: # %if.end
; CHECK-NEXT:    ret
entry:
  %ctpop = call i64 @llvm.ctpop.i64(i64 %x)
  %cmp1 = icmp ugt i64 %ctpop, 1
  %cmp2 = icmp sgt i64 %x, 0
  %or = or i1 %cmp2, %cmp1
  br i1 %or, label %if.end, label %if.else

if.else:
  %load = load i64, ptr %p, align 8
  br label %if.end

if.end:
  %res = phi i64 [0, %entry], [%load, %if.else]
  ret i64 %res
}
