[clang] [clang][CGExprScalar] Remove no-op ptr-to-ptr bitcast (NFC) (PR #72072)

Youngsuk Kim via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 13 07:04:14 PST 2023


https://github.com/JOE1994 updated https://github.com/llvm/llvm-project/pull/72072

>From b9db2565d3d2d251bde7cd84b704861d5b41bd14 Mon Sep 17 00:00:00 2001
From: JOE1994 <joseph942010 at gmail.com>
Date: Sun, 12 Nov 2023 20:04:44 -0500
Subject: [PATCH 1/2] [clang][CGExprScalar] Remove no-op ptr-to-ptr bitcast
 (NFC)

Remove bitcast added back in dcd74716f9d18 .
---
 clang/lib/CodeGen/CGExprScalar.cpp | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 1a7a3f97bb779a0..2faab20fc069ee7 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2227,14 +2227,6 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
     llvm::Value *V = CE->changesVolatileQualification()
                          ? EmitLoadOfLValue(CE)
                          : Visit(const_cast<Expr *>(E));
-    if (V) {
-      // CK_NoOp can model a pointer qualification conversion, which can remove
-      // an array bound and change the IR type.
-      // FIXME: Once pointee types are removed from IR, remove this.
-      llvm::Type *T = ConvertType(DestTy);
-      if (T != V->getType())
-        V = Builder.CreateBitCast(V, T);
-    }
     return V;
   }
 

>From f5e09e6ac45919a6e1fac6e4ee4520bda8aa502b Mon Sep 17 00:00:00 2001
From: JOE1994 <joseph942010 at gmail.com>
Date: Mon, 13 Nov 2023 10:02:28 -0500
Subject: [PATCH 2/2] Return immediately instead of storing retval to
 intermediate variable

---
 clang/lib/CodeGen/CGExprScalar.cpp | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 2faab20fc069ee7..641a984f2f1a0ec 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2224,10 +2224,8 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
     return Visit(const_cast<Expr*>(E));
 
   case CK_NoOp: {
-    llvm::Value *V = CE->changesVolatileQualification()
-                         ? EmitLoadOfLValue(CE)
-                         : Visit(const_cast<Expr *>(E));
-    return V;
+    return CE->changesVolatileQualification() ? EmitLoadOfLValue(CE)
+                                              : Visit(const_cast<Expr *>(E));
   }
 
   case CK_BaseToDerived: {



More information about the cfe-commits mailing list