[llvm] [InstCombine] Propagate exact flags in shift-combine transforms (PR #88340)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 15 18:54:15 PDT 2024
================
@@ -191,6 +191,77 @@ define <2 x i8> @shl_add_commute_vec(<2 x i8> %x, <2 x i8> %py) {
ret <2 x i8> %r
}
+define i8 @shl_add2(i8 %x, i8 %y) {
+; CHECK-LABEL: @shl_add2(
+; CHECK-NEXT: [[TMP1:%.*]] = lshr exact i8 [[Y:%.*]], 2
+; CHECK-NEXT: [[TMP2:%.*]] = add i8 [[TMP1]], [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[TMP2]], 63
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %l = shl i8 %x, 2
+ %a = add i8 %l, %y
+ %r = lshr exact i8 %a, 2
+ ret i8 %r
+}
+
+define i8 @double_lshr_exact(i8 %x, i8 %y) {
+; CHECK-LABEL: @double_lshr_exact(
+; CHECK-NEXT: [[TMP1:%.*]] = lshr exact i8 [[Y:%.*]], 2
+; CHECK-NEXT: [[R:%.*]] = lshr exact i8 [[TMP1]], [[Y1:%.*]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %l = lshr exact i8 %x, 2
+ %r = lshr exact i8 %l, %y
+ ret i8 %r
+}
+
+define i8 @double_lshr_no_exact(i8 %x, i8 %y) {
+; CHECK-LABEL: @double_lshr_no_exact(
+; CHECK-NEXT: [[L:%.*]] = lshr i8 [[X:%.*]], 2
+; CHECK-NEXT: [[R:%.*]] = lshr exact i8 [[L]], [[Y:%.*]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %l = lshr i8 %x, 2
+ %r = lshr exact i8 %l, %y
+ ret i8 %r
+}
+
+define i8 @double_lshr_no_exact2(i8 %x, i8 %y) {
+; CHECK-LABEL: @double_lshr_no_exact2(
+; CHECK-NEXT: [[TMP1:%.*]] = lshr exact i8 [[Y:%.*]], 2
+; CHECK-NEXT: [[R:%.*]] = lshr i8 [[TMP1]], [[Y1:%.*]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %l = lshr exact i8 %x, 2
+ %r = lshr i8 %l, %y
+ ret i8 %r
+}
+
+define i8 @double_lshr_exact2(i8 %x) {
+; CHECK-LABEL: @double_lshr_exact2(
+; CHECK-NEXT: [[R:%.*]] = lshr i8 [[X:%.*]], 5
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %l = lshr exact i8 %x, 2
+ %r = lshr exact i8 %l, 3
+ ret i8 %r
+}
----------------
nikic wrote:
Okay, so it looks like the exact flag doesn't actually get preserved in this case. Do you know why? Presumably there is some other fold that handles this earlier already.
https://github.com/llvm/llvm-project/pull/88340
More information about the llvm-commits
mailing list