Is there a difference between "lower" and "legalize" in TIR?

Thanks @kparzysz . I believe the argument can go both ways in here. If we view the overall IR as “staged”, lowering means we have a strategy to map them to the corresponding low level intrinsics.

While legalization means we remap the op by composing using other expressions, which still need to be lowered in order to remain valid in the target platform.

For example, mapping exp => llvm.exp is a way of lowering, but because llvm does not have sigmoid, imagine we have a sigmoid op, mapping sigmoid(x)=>1 /(1 + exp(-x)) will be called legalization, and we still need to map the exp to llvm.exp after legalize in order to run on the target platform.