I *think* we'd want this new variant, because we obviously
have better handling for add as compared to sub/not.
https://rise4fun.com/Alive/WMn
Fixes PR42457
Differential D63992
[InstCombine] Y - ~X --> X + Y + 1 fold (PR42457) lebedev.ri on Jul 1 2019, 5:40 AM. Authored by
Details I *think* we'd want this new variant, because we obviously https://rise4fun.com/Alive/WMn Fixes PR42457
Diff Detail
Event TimelineComment Actions Not sure which way to go here - a 'not' is considered a less complex op than arbitrary xor/add, and 'not' might be better for value tracking and subsequent instcombines. But the adds are reassociable/commutable. This might warrant a DAGCombiner patch to avoid regressions before we make the IR decision. x86 scalar looks better with add+inc: movl %edi, %eax notl %esi subl %esi, %eax vs. leal 1(%rsi,%rdi), %eax But AArch64 and PowerPC64LE appear to benefit from the 'not' with vector code: mvn v1.16b, v1.16b sub v0.4s, v0.4s, v1.4s vs. add v0.4s, v1.4s, v0.4s movi v1.4s, #1 add v0.4s, v0.4s, v1.4s And PPC: xxlnor 35, 35, 35 vsubuwm 2, 2, 3 vs. vspltisw 4, 1 vadduwm 2, 3, 2 vadduwm 2, 2, 4 If we do go in this direction, do we want to increment 1st to reduce the burden on -reassociation? Assuming it will do: cc'ing Eli in case he sees any other motivations to consider. Comment Actions Yes, we should probably teach DAGCombine to choose the right form for each target/type. It seems reasonable to prefer x+(y+1) over x-(-1-y), for reassociation etc. It's possible there could be some bad interaction at the interface between logical and arithmetic operations, which makes us miss some important optimization, but that doesn't seem likely to me. Comment Actions Great, thank you for the feedback! Comment Actions @RKSimon encountered https://bugs.llvm.org/show_bug.cgi?id=42486 while trying to write tests, PTAL. |