[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
Mon Jan 15 01:59:48 PST 2024


================
@@ -16,6 +16,19 @@ define i8 @shl_and(i8 %x, i8 %y) {
   ret i8 %sh1
 }
 
+define i8 @shl_and_non_imm(i8 %x, i8 %y) {
+; CHECK-LABEL: @shl_and_non_imm(
+; CHECK-NEXT:    [[SH0:%.*]] = shl i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = and i8 [[SH0]], [[Y]]
+; CHECK-NEXT:    [[SH1:%.*]] = shl i8 [[R]], 2
+; CHECK-NEXT:    ret i8 [[SH1]]
+;
+  %sh0 = shl i8 %x, %y
+  %r = and i8 %sh0, %y
+  %sh1 = shl i8 %r, 2
+  ret i8 %sh1
+}
----------------
nikic wrote:

I don't understand this test coverage. This test (and all the others you added) are not affected by the transform.

This transform always requires the shift amount to be constant. The difference would be in having a constant operand on the `and` here, not the `shl`. We would also need a multi-use scenario (see tests using `@use`).

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


More information about the llvm-commits mailing list