Hi all,
I am looking for a way to keep if-then and if-then-else constructs apart in IR.
Say we have the following construct:
if(foo) {
// More code
return 42;
}
// More code
return 21;
Assuming that function returns have been unified, we’ll end up with something like this in IR I presume:
if(foo) {
// More code
goto end;
}
// More code
goto end;
end:
// Phi node
return PhiVal;
This is equivalent to:
if(foo) {
// More code
goto end;
} else {
// More code
goto end;
}
end:
PhiVal = [ /* Assign value based on predecessor */ ];
return PhiVal;
Is there a way to tell where the IR came from, i.e. whether it originated in an if-then or if-then-else construct? Any pointers? Or in other words, can I figure out whether the basic block which is entered when the if condition evaluates to false is part of an else or not?
AFAICT, branch statements don’t differentiate between if-then and if-then-else constructs. The standard way would be to use post-dominance, but that wouldn’t work here as it would treat both cases the same way? (Also it is something I cannot use in my scenario, but that’s another story)
Many thanks,
Paul