[PATCH] D19087: [x86, ppc] prefer comparisons against zero for and+cmp sequences

Hal Finkel via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 14 09:17:53 PDT 2016


hfinkel added a comment.

In http://reviews.llvm.org/D19087#401302, @spatel wrote:

> In http://reviews.llvm.org/D19087#401155, @hfinkel wrote:
>
> > In http://reviews.llvm.org/D19087#401119, @spatel wrote:
> >
> > > In http://reviews.llvm.org/D19087#400599, @hfinkel wrote:
> > >
> > > > This certainly a good pattern to catch, but I'm not sure that CGP is the right place for this. We generally have things in CGP to work-around the fact that SDAG/ISel is basic-block local. This kind of thing seems much more natural as a something that should be in DAGCombine.
> > >
> > >
> > > Yes, I initially thought I'd do this as a DAGCombine, but then I realized that we'd need "isKnownToBeAPowerOfTwo()", and I don't see an SDNode equivalent for the IR version. I'm not sure where we draw the line between CGP and DAGCombine, but duplicating isKnownToBeAPowerOfTwo() scared me away.
> >
> >
> > Why? How do we select the instructions anyway? For x86 or ppc, would we not want to limit the applicability to constants? It needs to be a constant for rlwinm I'd imagine, and bt too?. For constants, we can check this with existing functionality.
>
>
> isKnownToBeAPowerOfTwo() is ~100 lines and recursive. We can approximate it using computeKnownBits(), but I think getting the full power of the IR version would mean duplicating the code.
>
> One of the x86 regression tests shows the case where a simple constant check won't do:
>
>   define i1 @and_cmp_const_power_of_two(i32 %x, i32 %y) {
>     %shl = shl i32 1, %y
>     %and = and i32 %x, %shl
>     %cmp = icmp ne i32 %and, %shl
>     ret i1 %cmp
>   }
>   
>
> X86TargetLowering::LowerToBT() uses computeKnownBits() to know that's a power-of-2 mask.


Okay, but in the end, the check used has to match the capabilities of the check used in the backend for lowering. In this case, it needs to use computeKnownBits(). Regardless, in this case, as I understand it, it is not enough to know that the number is some power of 2, we need to know which power of 2.


http://reviews.llvm.org/D19087





More information about the llvm-commits mailing list