[PATCH] D34822: [LVI] Constant-propagate a zero extension of the switch condition value through case edges
Hiroshi Yamauchi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 19 11:42:50 PDT 2017
yamauchi added a comment.
For more context:
Here's a test C program that demonstrates this issue (reduced from the Python 2.7 runtime eval loop code) :
void bar(int v);
int foo(unsigned char* p, int (*f)(int)) {
int op;
void* targets[256];
int i;
for (i = 0; i < 256; ++i) {
targets[i] = &&unknown_op;
}
targets[93] = &&TARGET_93;
targets[145] = &&TARGET_145;
for (;;) {
op = *p++;
dispatch_op:
switch (op) {
TARGET_93:
op = 93;
case 93: {
if (op != 93) {
f(42);
}
goto *targets[*p++];
}
TARGET_145:
op = 145;
case 145: {
op = *p++;
goto dispatch_op;
}
unknown_op:
default:
bar(op);
break;
}
}
return 0;
}
There's a control merge between "TARGET_93" (that the computed goto may jumps to) and "case 93" (that the normal switch control flow may jump to).
The value of 'op' at "case 93:" would be constant 93 regardless of the control flow.
So, we could eliminate the call to 'f'.
GCC does this whereas LLVM does not.
https://reviews.llvm.org/D34822
More information about the llvm-commits
mailing list