[llvm] [InstCombine] Reducing rust i128::midpoint instructions (PR #99614)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 19 07:07:44 PDT 2024


================
@@ -1483,6 +1483,47 @@ static Instruction *foldBoxMultiply(BinaryOperator &I) {
   return nullptr;
 }
 
+// Relating to the i128::midpoint in rust nightly 
+// we're finding this expression: ((Y ^ X) >> 1 + (Y & X))
+// with the i128 data type and reducing the amount of asm instructions
+// generated.
+static Instruction *foldMidpointExpression(BinaryOperator &I) {
+  Value *X, *Y;
+
+  if (!I.getType()->isIntegerTy(128))
+    return nullptr;
+
+  if (!match(&I, m_Add(m_LShr(m_Xor(m_Value(X), m_Value(Y)), m_ConstantInt()),
+                      m_And(m_Value(X), m_Value(Y)))))
----------------
dtcxzyw wrote:

```suggestion
                      m_c_And(m_Deferred(X), m_Deferred(Y)))))
```


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


More information about the llvm-commits mailing list