xref: /llvm-project/llvm/test/CodeGen/RISCV/pr84200.ll (revision 909ab0e0d1903ad2329ca9fdf248d21330f9437f)
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2; RUN: llc < %s -mtriple=riscv64 | FileCheck %s
3
4; The sub nuw produces poison if the input is not 0 or 1. We must insert a
5; freeze before converting the sub to AND so that we don't propagate poison.
6define i64 @foo(i64 %1) {
7; CHECK-LABEL: foo:
8; CHECK:       # %bb.0: # %entry
9; CHECK-NEXT:    li a1, 1
10; CHECK-NEXT:    sub a1, a1, a0
11; CHECK-NEXT:    sltiu a0, a0, 2
12; CHECK-NEXT:    xori a1, a1, 1
13; CHECK-NEXT:    neg a0, a0
14; CHECK-NEXT:    and a0, a0, a1
15; CHECK-NEXT:    ret
16entry:
17  %.urem.i = sub nuw i64 1, %1
18  %.cmp.i = icmp ugt i64 %1, 1
19  %2 = xor i64 %.urem.i, 1
20  %3 = select i1 %.cmp.i, i64 0, i64 %2
21  ret i64 %3
22}
23