[InstCombine] add test for udiv with shl divisor; NFC
authorSanjay Patel <spatel@rotateright.com>
Wed, 12 Oct 2022 15:36:27 +0000 (11:36 -0400)
committerSanjay Patel <spatel@rotateright.com>
Wed, 12 Oct 2022 15:53:02 +0000 (11:53 -0400)
This would solve an example from issue #58137 more
generally, but it may require adding a canonicalization
for shift + shift to shift + add.

llvm/test/Transforms/InstCombine/div-shift.ll

index 0f5d4e7..084b596 100644 (file)
@@ -892,3 +892,17 @@ define i8 @udiv_shl_shl_nuw_nsw2(i8 %x, i8 %y, i8 %z) {
   %d = udiv i8 %xz, %yz
   ret i8 %d
 }
+
+; TODO: X / (Y << Z) --> (X >> Z) / Y
+; https://alive2.llvm.org/ce/z/FjoN_A
+
+define i8 @udiv_shl_nuw_divisor(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @udiv_shl_nuw_divisor(
+; CHECK-NEXT:    [[S:%.*]] = shl nuw i8 [[Y:%.*]], [[Z:%.*]]
+; CHECK-NEXT:    [[D:%.*]] = udiv i8 [[X:%.*]], [[S]]
+; CHECK-NEXT:    ret i8 [[D]]
+;
+  %s = shl nuw i8 %y, %z
+  %d = udiv i8 %x, %s
+  ret i8 %d
+}