[llvm] Bail out jump threading on indirect branches (PR #103688)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 26 09:45:53 PST 2024
================
@@ -1028,7 +1028,14 @@ CanRedirectPredsOfEmptyBBToSucc(BasicBlock *BB, BasicBlock *Succ,
if (!BB->hasNPredecessorsOrMore(2))
return false;
- // Get single common predecessors of both BB and Succ
+ if (any_of(BBPreds, [](const BasicBlock *Pred) {
+ return isa<PHINode>(Pred->begin()) &&
----------------
hiraditya wrote:
do you mind sharing your test case? I tried replacing switch with if-else and moving the check to a function parameter but didn't get a miscompile. https://godbolt.org/z/xvs571nbj
```cpp
#include<stdio.h>
__attribute__((noinline))
int foo(int state) {
void* bytecode[2];
bytecode[0] = &&VM__OP_1;
bytecode[1] = &&VM__TERMINATE;
//int state = 0;
int index = 0;
while (1) {
if (state==0) {
goto *bytecode[index];
}
if (state == 1) {
printf("Unreachable\n");
// NOTE: THIS IS ONLY REACHABLE VIA INDIRECT GOTOS
VM__OP_1:
printf("VM__OP_1\n");
state = 2;
}
else if (state== 2) {
printf("OP_1:(instruction=%d)\n", index);
index++;
goto *bytecode[index];
}
}
VM__TERMINATE:
printf("TERMINATE:(instruction=%d)\n", index);
return 0;
}
int main() {
foo(0);
return 0;
}```
https://github.com/llvm/llvm-project/pull/103688
More information about the llvm-commits
mailing list