To use select, usually, there is a compare before select.
Presence of comparison will disable some opportunities to
optimize some code. Select and Compare is not associative
neither.
To use select, usually, there is a compare before select.
Presence of comparison will disable some opportunities to
optimize some code. Select and Compare is not associative
neither.
at the IR level LLVM already has pattern matching helpers for
identifying min/max idioms, here is part of a transform using
this, from InstructionSimplify.cpp:
// Signed variants on "max(a,b)>=a -> true".
if (match(LHS, m_SMax(m_Value(A), m_Value(B))) && (A == RHS || B == RHS)) {
if (A != RHS) std::swap(A, B); // smax(A, B) pred A.
EqP = CmpInst::ICMP_SGE; // "A == smax(A, B)" iff "A sge B".
// We analyze this as smax(A, B) pred A.
P = Pred;
}
At the codegen level, the same could be done. Also, if a target has a
max/min instruction it can transform compare+select to max/min, in fact
I'm pretty sure some targets do this already.
Yes, exactly. However, we need define Opcode MIN/MAX
Into ISDOpcodes.h. Do you like to add those two definitions
Into the tree?
No, it's only desirable to have opcodes if we intend to add generic lowering and optimizations for them. Since min / max can be represented with select, there is no need. Please use target specific opcodes to handle them.