[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
Wed Jan 17 03:23:23 PST 2024


================
@@ -16,6 +14,23 @@ define i8 @shl_and(i8 %x, i8 %y) {
   ret i8 %sh1
 }
 
+define i8 @shl_and_multiuse(i8 %x) {
+; CHECK-LABEL: @shl_and_multiuse(
+; CHECK-NEXT:    [[SH0:%.*]] = shl i8 [[X:%.*]], 3
+; CHECK-NEXT:    call void @use(i8 [[SH0]])
+; CHECK-NEXT:    [[R:%.*]] = shl i8 [[X]], 5
+; CHECK-NEXT:    [[SH1:%.*]] = and i8 [[R]], -96
+; CHECK-NEXT:    ret i8 [[SH1]]
+;
+  %sh0 = shl i8 %x, 3
+  %r = and i8 %sh0, 42
+  call void @use(i8 %sh0)
+  %sh1 = shl i8 %r, 2
+  ret i8 %sh1
+}
----------------
nikic wrote:

Okay, this is testing the right thing now. However, we don't need a multi-use variant of every single test.

It would be enough to have just one multi-use test with a constant (folds) and another with a variable (does not fold).

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


More information about the llvm-commits mailing list