[clang] [SCCP] [Transform] Adding ICMP folding for zext and sext in SCCPSolver (PR #67594)

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 27 12:25:36 PDT 2023


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 5ffbdd9ed5fb719b354e4a46acc8737c5b624f94 399f9d64cfde0761ac8278dd05ba704d879b1f5a -- clang/test/CodeGen/X86/min_max.c llvm/lib/Transforms/Utils/SCCPSolver.cpp
``````````

</details>

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

``````````diff
diff --git a/llvm/lib/Transforms/Utils/SCCPSolver.cpp b/llvm/lib/Transforms/Utils/SCCPSolver.cpp
index 09f64a925ab1..0038e8866c2c 100644
--- a/llvm/lib/Transforms/Utils/SCCPSolver.cpp
+++ b/llvm/lib/Transforms/Utils/SCCPSolver.cpp
@@ -195,56 +195,62 @@ static bool replaceSignedInst(SCCPSolver &Solver,
   }
   case Instruction::ICmp: {
     ICmpInst &ICmp = cast<ICmpInst>(Inst);
-  
+
     ZExtInst *Op0_zext = dyn_cast<ZExtInst>(ICmp.getOperand(0));
     SExtInst *Op0_sext = dyn_cast<SExtInst>(ICmp.getOperand(0));
-  
+
     ZExtInst *Op1_zext = dyn_cast<ZExtInst>(ICmp.getOperand(1));
     SExtInst *Op1_sext = dyn_cast<SExtInst>(ICmp.getOperand(1));
-  
+
     CastInst *Op0;
     CastInst *Op1;
-  
-    if (Op0_zext) Op0 = Op0_zext; else Op0 = Op0_sext;
-    if (Op1_zext) Op1 = Op1_zext; else Op1 = Op1_sext;
-  
+
+    if (Op0_zext)
+      Op0 = Op0_zext;
+    else
+      Op0 = Op0_sext;
+    if (Op1_zext)
+      Op1 = Op1_zext;
+    else
+      Op1 = Op1_sext;
+
     bool reversed = false;
-  
-    if (!Op0 || !Op1){
+
+    if (!Op0 || !Op1) {
       // Op0 and Op1 must be defined
       return false;
-    } 
-  
-    if (Op1_zext && (! Op0_zext)){
+    }
+
+    if (Op1_zext && (!Op0_zext)) {
       // We force Op0 to be a zext and reverse the arguments
       //   at the end if we swap
-      reversed = true; 
-  
+      reversed = true;
+
       std::swap(Op0_zext, Op1_zext);
       std::swap(Op0_sext, Op1_sext);
       std::swap(Op0, Op1);
     }
-  
-  
-    if(Op0->getType() != Op1->getType()){
+
+    if (Op0->getType() != Op1->getType()) {
       // extensions are not of the same type
       // This optimization is done in InstCombine
       return false;
     }
-  
+
     // ICMP (sext X) (sext y) => ICMP X, Y
     // ICMP (zext X) (zext y) => ICMP X, Y
     // ICMP (zext X) (sext Y) => ICMP X, Y  if X >= 0 and ICMP signed
-    if((Op0_zext && Op1_zext)
-       || (Op0_sext && Op1_sext) 
-       || (ICmp.isSigned() && Op0_zext && Op1_sext && isNonNegative(Op0_zext->getOperand(0)))){
-  
+    if ((Op0_zext && Op1_zext) || (Op0_sext && Op1_sext) ||
+        (ICmp.isSigned() && Op0_zext && Op1_sext &&
+         isNonNegative(Op0_zext->getOperand(0)))) {
+
       Value *X = Op0->getOperand(0);
       Value *Y = Op1->getOperand(0);
-      NewInst = CmpInst::Create(ICmp.getOpcode(), ICmp.getPredicate(), reversed ? Y : X, reversed ? X : Y, "", &Inst);
+      NewInst = CmpInst::Create(ICmp.getOpcode(), ICmp.getPredicate(),
+                                reversed ? Y : X, reversed ? X : Y, "", &Inst);
       break;
     }
-  
+
     return false;
   }
   default:

``````````

</details>


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


More information about the cfe-commits mailing list