[llvm] [InstCombine] Simplification for (-a * b) / (a * b). (PR #71768)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 00:44:09 PST 2023


================
@@ -1432,6 +1432,50 @@ define <2 x i8> @sdiv_sdiv_mul_nsw(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
   ret <2 x i8> %r
 }
 
+define i32 @sdiv_sub(i32 %arg) {
+; CHECK-LABEL: @sdiv_sub(
+; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq i32 [[ARG:%.*]], -2147483648
+; CHECK-NEXT:    [[DIV:%.*]] = select i1 [[TMP1]], i32 1, i32 -1
+; CHECK-NEXT:    ret i32 [[DIV]]
+;
+  %neg = sub i32 0, %arg
+  %div = sdiv i32 %neg, %arg
+  ret i32 %div
+}
----------------
nikic wrote:

Should also test swapped sdiv operands, the transform is valid for both cases: https://alive2.llvm.org/ce/z/dHddwH

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


More information about the llvm-commits mailing list