[llvm] [ValueTracking] Implement udiv support for isKnownNonNullFromDominatingCondition (PR #67282)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 25 01:49:05 PDT 2023


================
@@ -393,3 +393,27 @@ define i1 @inv_select_v_sle_nonneg(i8 %v, i8 %C, i8 %y) {
   %r = icmp eq i8 %s, 0
   ret i1 %r
 }
+
+; Check dominance of the udiv over the icmp.
+define i64 @incorrect_safe_div(i64 %n, i64 %d) {
+; CHECK-LABEL: @incorrect_safe_div(
+; CHECK-NEXT:    [[TMP1:%.*]] = udiv i64 [[N:%.*]], [[D:%.*]]
+; CHECK-NEXT:    ret i64 [[TMP1]]
+;
+  %1 = udiv i64 %n, %d
+  %2 = icmp eq i64 %d, 0
+  %3 = select i1 %2, i64 -1, i64 %1
+  ret i64 %3
+}
+
+; Check post-dominance of the udiv over the icmp.
----------------
nikic wrote:

Post-dominance is not the right term here. You want them to be in the same must-execute region.

You can also add a test variant with a call between the icmp and udiv, which should not fold.

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


More information about the llvm-commits mailing list