<div dir="ltr">Hello there,<div><br></div><div>I have a high level code which would look like that in C++:</div><div><br></div><div><div><font face="courier new, monospace">enum E { A, B, C };</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">E int2e(long i) {</font></div><div><font face="courier new, monospace"> switch(i) {</font></div><div><font face="courier new, monospace"> case 0: return A;</font></div>
<div><font face="courier new, monospace"> case 1: return B;</font></div><div><font face="courier new, monospace"> case 2: return C;</font></div><div><font face="courier new, monospace"> default: return A;</font></div>
<div><font face="courier new, monospace"> }</font></div><div><font face="courier new, monospace">}</font></div></div><div><br></div><div>It is compiled to this IR with O3 optimization:</div><div><br></div><div><div><font face="courier new, monospace">define i64 @int2e(i64 %i_arg) #0 {</font></div>
<div><font face="courier new, monospace">entry:</font></div><div><font face="courier new, monospace"> switch i64 %i_arg, label %label_case1 [</font></div><div><font face="courier new, monospace"> i64 2, label %label_case3</font></div>
<div><font face="courier new, monospace"> i64 1, label %label_case2</font></div><div><font face="courier new, monospace"> ]</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">label_case1: ; preds = %entry, %label_case3, %label_case2</font></div>
<div><font face="courier new, monospace"> %merge = phi i64 [ %i_arg, %label_case2 ], [ %i_arg, %label_case3 ], [ 0, %entry ]</font></div><div><font face="courier new, monospace"> ret i64 %merge</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">label_case2: ; preds = %entry</font></div><div><font face="courier new, monospace"> br label %label_case1</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">label_case3: ; preds = %entry</font></div><div><font face="courier new, monospace"> br label %label_case1</font></div><div><font face="courier new, monospace">}</font></div>
</div><div><br></div><div>In the result IR `phi` instruction has 3 branches, but two first of them returns the same value. Shouln't it be optimized?</div><div><br></div><div>- Paweł</div></div>