Patterns were added to substitute comparison and logic operations with min and logic operations.
Pattern.1
i = a < c
j = b < c
res = i or j
changes to:
m = min(a, b)
res = m < c
Pattern.2
i = a >= c
j = b >= c
res = i and j // negation of the result from Pattern.1
changes to:
m = min(a, b)
tmp = m < c
res = tmp xor 1
Pattern.2 is similar to Pattern.1 except there is no sgeu instruction and result has to be inverted with xor 1.
This patch can resolve this issue: https://github.com/llvm/llvm-project/issues/56518
The DAG for this before isel looks like
SelectionDAG has 16 nodes: t0: ch = EntryToken t2: i64,ch = CopyFromReg t0, Register:i64 %0 t4: i64,ch = CopyFromReg t0, Register:i64 %1 t22: i64 = setcc t4, t2, setult:ch t6: i64,ch = CopyFromReg t0, Register:i64 %2 t19: i64 = setcc t6, t2, setult:ch t26: i64 = or t22, t19 t27: i64 = xor t26, Constant:i64<1> t13: ch,glue = CopyToReg t0, Register:i64 $x10, t27 t14: ch = RISCVISD::RET_FLAG t13, Register:i64 $x10, t13:1There is no AND, the XOR with 1 was already created.