[llvm] [Support] Adding fast-path for KnownBits's udiv when RHS is contant (PR #189779)

Max Graey via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 1 02:59:33 PDT 2026


================
@@ -1209,6 +1209,26 @@ KnownBits KnownBits::udiv(const KnownBits &LHS, const KnownBits &RHS,
     return Known;
   }
 
+  if (RHS.isConstant()) {
----------------
MaxGraey wrote:

I thought about reusing `LHS.lshr`, but it’s quite cumbersome for this specific case and includes conflict handling, it has loops (even though our case would only require a single iteration) and a lot of branching. Here, one of the goals is not only to improve accuracy but also to speed up the computation itself for this particular case. 

What about Divisor.isOne()? Do you think that’s too rare a case?

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


More information about the llvm-commits mailing list