This patch does two things:
- fix the typo that intrinsic mfvscr should be with no readmem property
- since VSCR is not modeled yet, add has side effect for SAT bit clobber intrinsics/instructions.
Paths
| Differential D90807
[PowerPC] add has side effect for SAT bit clobber intrinsics/instructions ClosedPublic Authored by shchenz on Nov 4 2020, 6:08 PM.
Details
Summary This patch does two things:
Diff Detail
Event TimelineComment Actions This change is fine as it is. However, since we don't model the VSCR and we mark saturating intrinsics as having no sideeffects, we can miscompile wrt. this instruction/intrinsic. vector int test(vector int a, vector int b, vector int aa, vector signed short *__restrict FromVSCR) { vector int c = __builtin_altivec_vsumsws(a, b); // Clear the SAT bit in vscr. __builtin_altivec_mtvscr((vector signed int){0, 0, 0, 0}); c += a + b + (vector int)__builtin_altivec_vpkswus(a, b); // Check for saturation from first vpkswus. *FromVSCR = __builtin_altivec_mfvscr(); // This vpkswus must not be moved before mfvscr. return c + (vector int)__builtin_altivec_vpkswus(b, aa); } Only the first vpkswus must be between the mtvscr and mfvscr. clang -O3 b.c -S -o - -mcpu=power9 vsumsws 5, 2, 3 xxlxor 32, 32, 32 mtvscr 0 vadduwm 0, 3, 2 vpkswus 2, 2, 3 vpkswus 3, 3, 4 # if this one saturates and the previous one doesn't, we have the wrong result mfvscr 1 stxv 33, 0(9) vadduwm 4, 0, 5 vadduwm 2, 4, 2 vadduwm 2, 2, 3 Comment Actions update according comments: shchenz retitled this revision from [PowerPC] no readmem property for intrinsics mfvscr to [PowerPC] add has side effect for SAT register clobber intrinsics.Nov 5 2020, 6:58 AM Comment Actions@nemanjai Hi, thanks for your comments. I did a further step to add has side effect property for SAT bit clobber intrinsics in the new patch. Could you please help to have another look? shchenz retitled this revision from [PowerPC] add has side effect for SAT register clobber intrinsics to [PowerPC] add has side effect for SAT bit clobber intrinsics.Nov 5 2020, 7:01 AM
shchenz retitled this revision from [PowerPC] add has side effect for SAT bit clobber intrinsics to [PowerPC] add has side effect for SAT bit clobber intrinsics/instructions. Comment Actions1: add side effect flag for instructions too.
Comment Actions LGTM now. But hold on for some days to see if @nemanjai has more comments. We need some follow up to revisit the floating point instructions and set the sideeffects flag accordingly before they are modelled in fact. This revision is now accepted and ready to land.Dec 15 2020, 7:06 PM This revision was landed with ongoing or failed builds.Dec 20 2020, 5:05 PM Closed by commit rG564066524ad0: [PowerPC] add has side effect for SAT bit clobber intrinsics/instructions (authored by shchenz). · Explain Why This revision was automatically updated to reflect the committed changes. Comment Actions Thank you so much for fixing this and I'm sorry I didn't get around to going over it sooner. Comment Actions
Hah, it doesn't matter. Thanks for your test cases ^^
Revision Contents
Diff 313006 llvm/include/llvm/IR/IntrinsicsPowerPC.td
llvm/lib/Target/PowerPC/PPCInstrAltivec.td
llvm/test/CodeGen/PowerPC/sat-register-clobber.ll
|
I think, we need to set the side effect in the .td to avoid scheduling schedule them.