[llvm] [InstCombine] Resolve TODO: Remove one-time check if other logic operand (Y) is constant (PR #77973)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 19 12:12:54 PST 2024


================
@@ -29,6 +31,21 @@ define <2 x i8> @shl_and_nonuniform(<2 x i8> %x, <2 x i8> %y) {
   ret <2 x i8> %sh1
 }
 
+define <2 x i8> @shl_and_nonuniform_multiuse(<2 x i8> %x) {
+; CHECK-LABEL: @shl_and_nonuniform_multiuse(
+; CHECK-NEXT:    [[SH0:%.*]] = shl <2 x i8> [[X:%.*]], <i8 3, i8 4>
+; CHECK-NEXT:    call void @use1(<2 x i8> [[SH0]])
+; CHECK-NEXT:    [[TMP1:%.*]] = shl <2 x i8> [[X]], <i8 5, i8 4>
+; CHECK-NEXT:    [[SH1:%.*]] = and <2 x i8> [[TMP1]], <i8 -88, i8 42>
+; CHECK-NEXT:    ret <2 x i8> [[SH1]]
+;
+  %sh0 = shl <2 x i8> %x, <i8 3, i8 4>
+  %r = and <2 x i8> %sh0, <i8 42, i8 42> ; constant operand on the 'and'
+  call void @use1(<2 x i8> %sh0)
+  %sh1 = shl <2 x i8> %r, <i8 2, i8 0>
+  ret <2 x i8> %sh1
+}
----------------
nikic wrote:

Okay, this is close to what we want now. Can you please move this next to `lshr_or_extra_use` and make it more similar to that test (i.e. use same types/operations, just with the binop operand being a constant)? That way we get the clear symmetry between the transform happening in one case but not the other.

https://github.com/llvm/llvm-project/pull/77973


More information about the llvm-commits mailing list