alive2 icon indicating copy to clipboard operation
alive2 copied to clipboard

Loop PHI swap produces an incorrect result

Open Forever119 opened this issue 3 weeks ago • 0 comments

After two loop iterations with mutually dependent PHI nodes, alive-exec returns 0 instead of 1.

Program

define i32 @main() {
entry:
  br label %loop
loop:
  %a = phi i32 [1, %entry], [%b, %loop]
  %b = phi i32 [2, %entry], [%a, %loop]
  %i = phi i32 [0, %entry], [%n, %loop]
  %n = add i32 %i, 1
  %c = icmp ult i32 %n, 2
  br i1 %c, label %loop, label %exit
exit:
  %d = sub i32 %a, %b
  ret i32 %d
}

Output

%a = #x00000002
%b = #x00000002
%i = #x00000001
%n = #x00000002
%c = #b0
  >> Jump to %exit

%d = #x00000000
Returned #x00000000 / non-poison=true

Forever119 avatar Nov 09 '26 02:11 Forever119