llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

If the `getIntegerConstantExpr()` calls succeed, we can as well replace the 
`BinaryOperator` children with `ConstantExpr`s wrapping the previous LHS/RHS.

This shows small speedups: 
https://llvm-compile-time-tracker.com/compare.php?from=cc8c941e17558ba427de06e72c8ad96d7b17ced1&amp;to=112af8e62e734938547d50eeb7b416c8dd666f45&amp;stat=instructions:u

---
Full diff: https://github.com/llvm/llvm-project/pull/151464.diff


1 Files Affected:

- (modified) clang/lib/Sema/SemaChecking.cpp (+17-1) 


``````````diff
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index c74b67106ad74..9b2eed3f5270f 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -11374,11 +11374,27 @@ static void AnalyzeComparison(Sema &S, BinaryOperator 
*E) {
         LHS->getIntegerConstantExpr(S.Context);
 
     // We don't care about expressions whose result is a constant.
-    if (RHSValue && LHSValue)
+    if (RHSValue && LHSValue) {
+      auto *LHSCE = ConstantExpr::Create(S.Context, LHS, APValue(*LHSValue));
+      auto *RHSCE = ConstantExpr::Create(S.Context, RHS, APValue(*RHSValue));
+      E->setLHS(LHSCE);
+      E->setRHS(RHSCE);
       return AnalyzeImpConvsInComparison(S, E);
+    }
 
     // We only care about expressions where just one side is literal
     if ((bool)RHSValue ^ (bool)LHSValue) {
+
+      if (LHSValue) {
+        auto *LHSCE = ConstantExpr::Create(S.Context, LHS, APValue(*LHSValue));
+        E->setLHS(LHSCE);
+        LHS = LHSCE;
+      } else if (RHSValue) {
+        auto *RHSCE = ConstantExpr::Create(S.Context, RHS, APValue(*RHSValue));
+        E->setRHS(RHSCE);
+        RHS = RHSCE;
+      }
+
       // Is the constant on the RHS or LHS?
       const bool RhsConstant = (bool)RHSValue;
       Expr *Const = RhsConstant ? RHS : LHS;

``````````

</details>


https://github.com/llvm/llvm-project/pull/151464
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to