%1:g8rc = RLWINM8 %0:g8rc, 0, 16, 9
%2:g8rc = RLWINM8 killed %1:g8rc, 0, 0, 31
->
%2:g8rc = RLWINM8 %0:g8rc, 0, 16, 9
The above folding is wrong. Before transformation, %2:g8rc is 32 bit value. After transformation, %2:g8rc becomes a 64 bit value.
Differential D71833
[PowerPC] if value type is changed after folding rlwinm, stop folding Authored by shchenz on Dec 23 2019, 3:45 AM.
Details
%1:g8rc = RLWINM8 %0:g8rc, 0, 16, 9 -> %2:g8rc = RLWINM8 %0:g8rc, 0, 16, 9 The above folding is wrong. Before transformation, %2:g8rc is 32 bit value. After transformation, %2:g8rc becomes a 64 bit value.
Diff Detail
Event TimelineComment Actions Thanks for finding the bug in the testcases. I have modified them in NFC patch https://reviews.llvm.org/rG79b3325be0b016fdc1a2c55bce65ec9f1e5f4eb6 Could you please help to be more specific about the invalid case in the description? Below c code gives a valid result: #include <stdio.h>
#define rlwinm( output, input, sh, mb, me ) \
__asm__( "rlwinm %0, %1, %2, %3, %4" \
: "=r"(output) \
: "r"(input), "i"(sh), "i"(mb), "i"(me) \
: )
int main()
{
unsigned long y,z,t ;
int i = 0;
for (unsigned x = 0; x < 4294967295; x++) {
rlwinm( y, x, 27, 30, 10) ;
rlwinm( z, y, 19, 0, 12);
rlwinm(t, x, 14, 11, 12);
if (z != t) {
printf("0x%016lX -> 0x%016lX, 0x%016lX\n", x, y, z);
printf("0x%016lX -> 0x%016lX\n", x, t);
i = 100;
break;
}
}
if (i == 0)
printf("valid\n");
else
printf("invalid\n");
return 0;
}So I guess %2:gprc = RLWINM %1:gprc, 27, 30, 10 %3:gprc = RLWINM %2:gprc, 19, 0, 12 should always be equal to %3:gprc = RLWINM %1, 14, 11, 12 for type i32 and i64 also?
Comment Actions Seems there is indeed some bug for current folding. If the wrap relationship between mb and me for folding result rlwinm is different with he wrap relationship in MI. rlwinm1 reg1, sh1, mb1, me1 -> rlwinm2 reg2, sh2, mb2, me2 If (mb1 > me1 && mb2 < me2), then rlwinm1 get 64 bit value, rlwinm2 get 32 bit value; The above two cases should be wrong. But I think the case in the description should be a valid transform. Comment Actions This is the bad transformation: %1:g8rc = RLWINM8 %0:g8rc, 0, 16, 9 %2:g8rc = RLWINM8 killed %1:g8rc, 0, 0, 31 -> %2:g8rc = RLWINM8 %0:g8rc, 0, 16, 9 Comment Actions We need another patch to fix the dead instruction removal for record form I think.
Comment Actions I would suggest to retitle it to be more descriptive about code behavior, like 'Add check' blah blah. Describe what bugs it can fix in summary field. Comment Actions LGTM with some minor nit.
| ||||||||||||||||||||||||||
We can delete the SrcMI only if it is not a record form?