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
Paths
| Differential D72019
[X86] Use carry flag from add for (seteq (add X, -1), -1). ClosedPublic Authored by craig.topper on Dec 30 2019, 2:53 PM.
Details Summary 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.
This revision is now accepted and ready to land.Dec 31 2019, 1:52 PM Closed by commit rG1cc8a74de345: [X86] Use carry flag from add for (seteq (add X, -1), -1). (authored by craig.topper). · Explain WhyDec 31 2019, 3:26 PM This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 235734 llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/pr44412.ll
|
Make this a static helper, so we're not duplicating the code in EmitTest()?
Also, can use a for-range loop?