[PATCH] D29687: [TargetLowering] check for sign-bit comparisons in SimplifyDemandedBits

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 8 08:03:05 PST 2017


spatel added inline comments.


================
Comment at: lib/CodeGen/SelectionDAG/TargetLowering.cpp:770
+      // TODO: Should we check for other forms of sign-bit comparisons?
+      // Examples: X <= -1, X >= 0
+    }
----------------
spatel wrote:
> RKSimon wrote:
> > Add test cases for these?
> I'm not sure we want to bloat it up with those cases yet; that's why I made it a TODO? rather than a FIXME.
> Instcombine already canonicalizes the X <= -1 variant to X < 0. It doesn't know to change X > -1 to X < 0 and swap the select operands, but I think that's just an IR canonicalization oversight, so I was planning to fix that.
> 
> So if we add codegen tests for those variants, it's only because a non-canonical select pattern has been created in the backend. I'd like to find evidence of that happening before adding code or tests for it.
Also, there's a hint in the test variable names for this shift/trunc canonicalization to X < 0:

  define <4 x i32> @signbit_sel_v4i32(<4 x i32> %x, <4 x i32> %y, <4 x i32> %mask) {
    %sh = lshr <4 x i32> %mask, <i32 31, i32 31, i32 31, i32 31>
    %tr = trunc <4 x i32> %sh to <4 x i1>
    %z = select <4 x i1> %tr, <4 x i32> %x, <4 x i32> %y
    ret <4 x i32> %z
  }

$ opt -instcombine -S foo.ll
  define <4 x i32> @signbit_sel_v4i32(<4 x i32> %x, <4 x i32> %y, <4 x i32> %mask) {
    %tr = icmp slt <4 x i32> %mask, zeroinitializer
    %z = select <4 x i1> %tr, <4 x i32> %x, <4 x i32> %y
    ret <4 x i32> %z
  }



https://reviews.llvm.org/D29687





More information about the llvm-commits mailing list