-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mips] After a26f1bf67ec, Bad machine code: Using an undefined physical register #51033
Comments
assigned to @jrtc27 |
Yes; it looks like an error from the backend where it expected a physical register. Register allocation should be turning all virtual registers into physical registers. If you do It could be that a pass is being run after register allocation that thinks it's still permitted to use virtual registers, but I'm pretty sure that's not allowed.
That a change to middle end optimization pass orderings exposed a bug in the backend is likely just a red herring. Thanks for taking the time to report though with reproducers! |
The last "Dump After" lines are: *** IR Dump After Live Stack Slot Analysis (livestacks) ***:*** IR Dump After Virtual Register Map (virtregmap) ***:*** IR Dump After Live Register Matrix (liveregmatrix) ***:so that Live Register Matrix seems a pretty likely candidate. :) |
Undefined physical register means that the register in question does not have a live definition at time of use (and is not reserved). |
Ok it looks like the generated use of $v1 straddles a PseudoSELECT_I, whose expansion splits the basic block into multiple, and then dead-mi-elimination thinks the definition in an earlier basic block is dead. Presumably the expansion is missing a recompilation of live-ins/outs of the basic blocks in question. |
Fixed by f5755c0, thanks! |
Not fixed in 13 though, so that's still affected. Don't know if this should stay open until it's back ported, otherwise it might be lost as a blocking bug of the 13.0.1 release? |
Oh right, let's keep it open then, so it gets the attention of the 13.0.1 release manager (Tom ?) |
Merged: 47f53ee |
mentioned in issue #51489 |
Extended Description
This backend error appeared when compiling the FreeBSD base system for mips or mips64 with clang 13:
*** Bad machine code: Using an undefined physical register ***
fatal error: error in backend: Found 1 machine code errors.
Bisection shows this error starts occurring after a26f1bf67ec ("[PassManager] Run additional LICM before LoopRotate "), so I am suspecting that this exposes a latent bug somewhere in the Mips backend? (As these test cases seem to work fine on other architectures.)
Minimized test case for 32-bit mips:
// clang -cc1 -triple mips-- -S -mrelocation-model static -target-cpu mips2 -O2 preen-min.c
typedef struct {
int a[0];
} b;
b c;
extern _Thread_local b *d;
int e, f, ay;
struct {
int g;
int h;
} * k;
char *ax;
b *l() {
if (d)
return d;
return &c;
}
int m() {
int i = 0, j = i;
f = l()->a[j];
return e;
}
char *n();
void o();
void q() {
if (k)
o(&k->h, k);
}
void o(char *r, int *s, int *t) {
char aw = *s;
char *p = n();
if (p)
p = &aw;
for (; *p && m(); p++)
for (; 0; ay = *t)
;
ax = r;
}
Minimized test case for 64-bit mips (looking very similar, though derived from a very different source file):
// clang -cc1 -triple mips64-- -S -target-cpu mips3 -O2 -ftls-model=initial-exec tw-min.c
typedef struct {
int a[0];
} b;
b *c;
extern _Thread_local b *d;
int e, f;
b *g() {
if (d)
return d;
return c;
}
int h(j) {
int i = j;
e = g()->a[i];
return 1;
}
void k() {
int *a;
for (a = 0; f;)
if (0 ?: h) {
int b;
a++;
if (*a) {
b = 0;
a++;
}
for (; h(*a);)
;
}
}
The text was updated successfully, but these errors were encountered: