Currently LLVM optimizes the code below:
define i8 @foo(i8 %cond) { entry: switch i8 %cond, label %default [ i8 -1, label %sw.-1 i8 0, label %sw.0 i8 1, label %sw.1 ] default: unreachable sw.-1: br label %merge sw.0: br label %merge sw.1: br label %merge merge: %ret = phi i8 [ 1, %sw.1 ], [ 0, %sw.0 ], [ -1, %sw.-1 ] ret i8 %ret }
to:
define i8 @foo(i8 %cond) { ret i8 %cond }
But once we make @foo return larger types, say i32 it no longer
optimizes. This patch covers such cases.
All inputs of a phi will have the same size (which is the same as the phi result type width), so computing a max in a loop doesn't make sense to me.