[PATCH] D150922: [KnownBits] Return `0` for poison {s,u}div inputs
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 18 17:38:31 PDT 2023
goldstein.w.n created this revision.
goldstein.w.n added reviewers: foad, nikic, RKSimon.
Herald added subscribers: pmatos, asb, StephenFan, hiraditya, jgravelle-google, sbc100, dschuff.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.
It seems consistent to always return zero for known poison rather than
varying the value. We do the same elsewhere.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D150922
Files:
llvm/lib/Support/KnownBits.cpp
llvm/test/CodeGen/WebAssembly/pr59626.ll
Index: llvm/test/CodeGen/WebAssembly/pr59626.ll
===================================================================
--- llvm/test/CodeGen/WebAssembly/pr59626.ll
+++ llvm/test/CodeGen/WebAssembly/pr59626.ll
@@ -13,6 +13,9 @@
; CHECK-32-NEXT: i32.const 0
; CHECK-32-NEXT: i32.store16 0
; CHECK-32-NEXT: local.get 1
+; CHECK-32-NEXT: i32.const 0
+; CHECK-32-NEXT: i32.store8 2
+; CHECK-32-NEXT: local.get 1
; CHECK-32-NEXT: local.get 0
; CHECK-32-NEXT: i8x16.splat
; CHECK-32-NEXT: v128.store16_lane 0, 0
Index: llvm/lib/Support/KnownBits.cpp
===================================================================
--- llvm/lib/Support/KnownBits.cpp
+++ llvm/lib/Support/KnownBits.cpp
@@ -546,6 +546,12 @@
assert(!LHS.hasConflict() && !RHS.hasConflict() && "Bad inputs");
KnownBits Known(BitWidth);
+ if (LHS.isZero() || RHS.isZero()) {
+ // Result is either known Zero or Poison. Return Zero either way.
+ Known.setAllZero();
+ return Known;
+ }
+
APInt Num, Denom;
// Positive -> true
// Negative -> false
@@ -618,6 +624,12 @@
assert(!LHS.hasConflict() && !RHS.hasConflict());
KnownBits Known(BitWidth);
+ if (LHS.isZero() || RHS.isZero()) {
+ // Result is either known Zero or Poison. Return Zero either way.
+ Known.setAllZero();
+ return Known;
+ }
+
// We can figure out the minimum number of upper zero bits by doing
// MaxNumerator / MinDenominator. If the Numerator gets smaller or Denominator
// gets larger, the number of upper zero bits increases.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150922.523615.patch
Type: text/x-patch
Size: 1542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230519/9d85fde8/attachment.bin>
More information about the llvm-commits
mailing list