[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
+}
----------------
nikic wrote:

This test (and the next two) are useless in that the pattern only works if both shift amounts are constants. This does not actually trigger the fold.

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


More information about the llvm-commits mailing list