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

via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 19 07:07:17 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 401d7bcabc0affc38a6e52ffad782eedf0a5ec5a 87a34e6a2b143b822177422c1853a885371b60fa --extensions cpp -- llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index b857150fec..f6da4835f7 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1483,7 +1483,7 @@ static Instruction *foldBoxMultiply(BinaryOperator &I) {
   return nullptr;
 }
 
-// Relating to the i128::midpoint in rust nightly 
+// 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.
@@ -1494,29 +1494,32 @@ static Instruction *foldMidpointExpression(BinaryOperator &I) {
     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)))))
+                       m_And(m_Value(X), m_Value(Y)))))
     return nullptr;
 
-  IRBuilder<> Builder(&I); 
+  IRBuilder<> Builder(&I);
   Module *Mod = I.getModule();
 
   // Create the call llvm.uadd.with.overflow.i128
-  Function *UAddWithOverflow = Intrinsic::getDeclaration(Mod, Intrinsic::uadd_with_overflow, 
-      Type::getInt128Ty(Mod->getContext()));
+  Function *UAddWithOverflow = Intrinsic::getDeclaration(
+      Mod, Intrinsic::uadd_with_overflow, Type::getInt128Ty(Mod->getContext()));
   CallInst *UAddCall = Builder.CreateCall(UAddWithOverflow, {Y, X});
-  UAddCall->setTailCall();  // Mark the call as a tail call
-  
-  // Extract the sum and the 
+  UAddCall->setTailCall(); // Mark the call as a tail call
+
+  // Extract the sum and the
   Value *Sum = Builder.CreateExtractValue(UAddCall, 0);
   Value *Overflow = Builder.CreateExtractValue(UAddCall, 1);
 
   // Create the right shift for the sum element of
   // overflow
-  Value *LShrVal = Builder.CreateLShr(Sum, ConstantInt::get(Type::getInt128Ty(I.getContext()), 1));
+  Value *LShrVal = Builder.CreateLShr(
+      Sum, ConstantInt::get(Type::getInt128Ty(I.getContext()), 1));
 
   // Create the select instruction
-  Value *SelectVal = Builder.CreateSelect(Overflow,
-      ConstantInt::get(Type::getInt128Ty(I.getContext()), APInt(128, 1).shl(127)), 
+  Value *SelectVal = Builder.CreateSelect(
+      Overflow,
+      ConstantInt::get(Type::getInt128Ty(I.getContext()),
+                       APInt(128, 1).shl(127)),
       ConstantInt::get(Type::getInt128Ty(I.getContext()), 0));
 
   Instruction *OrVal = BinaryOperator::CreateOr(LShrVal, SelectVal);
@@ -1548,7 +1551,7 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
 
   if (Instruction *R = foldMidpointExpression(I))
     return R;
-  
+
   if (Instruction *R = factorizeMathWithShlOps(I, Builder))
     return R;
 

``````````

</details>


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


More information about the llvm-commits mailing list