[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
Tue Jan 16 01:08:34 PST 2024
================
@@ -514,3 +857,53 @@ define <2 x i64> @lshr_sub_undef(<2 x i64> %x, <2 x i64> %py) {
%sh1 = lshr <2 x i64> %r, <i64 7, i64 undef>
ret <2 x i64> %sh1
}
+
+define <2 x i64> @lshr_sub_undef_constant(<2 x i64> %x) {
+; CHECK-LABEL: @lshr_sub_undef_constant(
+; CHECK-NEXT: [[SH0:%.*]] = lshr <2 x i64> [[X:%.*]], <i64 5, i64 undef>
+; CHECK-NEXT: [[R:%.*]] = sub <2 x i64> <i64 42, i64 42>, [[SH0]]
+; CHECK-NEXT: [[SH1:%.*]] = lshr <2 x i64> [[R]], <i64 7, i64 undef>
+; CHECK-NEXT: ret <2 x i64> [[SH1]]
+;
+ %sh0 = lshr <2 x i64> %x, <i64 5, i64 undef>
+ %r = sub <2 x i64> <i64 42, i64 42>, %sh0
+ %sh1 = lshr <2 x i64> %r, <i64 7, i64 undef>
+ ret <2 x i64> %sh1
+}
+
+define i8 @multi_use_constant(i8 %x, i8 %y) {
+; CHECK-LABEL: @multi_use_constant(
+; CHECK-NEXT: [[SH0:%.*]] = lshr i8 [[X:%.*]], 3
+; CHECK-NEXT: [[R:%.*]] = add nuw nsw i8 [[SH0]], -42
+; CHECK-NEXT: call void @func(i8 [[R]])
+; CHECK-NEXT: [[SH1:%.*]] = lshr i8 [[R]], 2
+; CHECK-NEXT: ret i8 [[SH1]]
+;
+ %sh0 = lshr i8 %x, 3
+ %r = sub i8 %sh0, 42
+ call void @func(i8 %r)
----------------
nikic wrote:
This is getting closer, but still testing the wrong thing. The transform always requires the binop to be one-use, your change is about the *shift*. You should pass `i8 %sh0` instead of `i8 %r` here.
https://github.com/llvm/llvm-project/pull/77973
More information about the llvm-commits
mailing list