[llvm] [MemorySanitizer] Use getelementptr instead of ptrtoint+add+inttoptr (PR #161392)

Alexander Richardson via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 30 10:07:48 PDT 2025


================
@@ -1923,20 +1923,20 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
   ///
   /// Shadow = ParamTLS+ArgOffset.
   Value *getShadowPtrForArgument(IRBuilder<> &IRB, int ArgOffset) {
-    Value *Base = IRB.CreatePointerCast(MS.ParamTLS, MS.IntptrTy);
-    if (ArgOffset)
-      Base = IRB.CreateAdd(Base, ConstantInt::get(MS.IntptrTy, ArgOffset));
-    return IRB.CreateIntToPtr(Base, IRB.getPtrTy(0), "_msarg");
+    if (ArgOffset == 0)
+      return MS.ParamTLS;
+    return IRB.CreatePtrAdd(MS.ParamTLS,
+                            ConstantInt::get(MS.IntptrTy, ArgOffset));
   }
 
   /// Compute the origin address for a given function argument.
   Value *getOriginPtrForArgument(IRBuilder<> &IRB, int ArgOffset) {
     if (!MS.TrackOrigins)
       return nullptr;
-    Value *Base = IRB.CreatePointerCast(MS.ParamOriginTLS, MS.IntptrTy);
-    if (ArgOffset)
-      Base = IRB.CreateAdd(Base, ConstantInt::get(MS.IntptrTy, ArgOffset));
-    return IRB.CreateIntToPtr(Base, IRB.getPtrTy(0), "_msarg_o");
+    if (ArgOffset == 0)
+      return MS.ParamOriginTLS;
+    return IRB.CreatePtrAdd(MS.ParamOriginTLS,
+                            ConstantInt::get(MS.IntptrTy, ArgOffset));
----------------
arichardson wrote:

```suggestion
    return IRB.CreatePtrAdd(MS.ParamOriginTLS,
                            ConstantInt::get(MS.IntptrTy, ArgOffset));
```
The zero check seems uneccessary since that will be folded anyway? Or does it make a significant difference to compile time?

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


More information about the llvm-commits mailing list