If we just subtracted 1 and are checking if the result is -1. We can use the carry flag from the ADD instead of an explicit CMP. I'm using the same checks for the add users as EmitTest.
Fixes PR44412
Differential D72019
[X86] Use carry flag from add for (seteq (add X, -1), -1). craig.topper on Dec 30 2019, 2:53 PM. Authored by
Details If we just subtracted 1 and are checking if the result is -1. We can use the carry flag from the ADD instead of an explicit CMP. I'm using the same checks for the add users as EmitTest. Fixes PR44412
Diff Detail Event TimelineComment Actions Invert the condition. Despite what the PR said, it should be jb to the top of the loop not jae. The original code condition was jne on a compare with -1. If the add produce a value != -1, then the carry flag is set since -1 plus anything but 0 will have unsigned overflow and produce a value other than -1. Only 0+-1 produces -1 and it does it without overflowing.
|
Make this a static helper, so we're not duplicating the code in EmitTest()?
Also, can use a for-range loop?