Skip to content

Conversation

mmha
Copy link
Contributor

@mmha mmha commented Sep 8, 2025

This patch replaces all uses of replaceAllUseWith with replaceOp. This fixes a number of regressions post #155244.

@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Sep 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 8, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clangir

Author: Morris Hafner (mmha)

Changes

This patch replaces all uses of replaceAllUseWith with replaceOp. This fixes a number of regressions post #155244.


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

1 Files Affected:

  • (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+2-4)
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index ee9f58c829ca9..f8dac2aa02a0c 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -1355,8 +1355,7 @@ mlir::LogicalResult CIRToLLVMConstantOpLowering::matchAndRewrite(
     } else {
       const mlir::Value initVal =
           lowerCirAttrAsValue(op, op.getValue(), rewriter, typeConverter);
-      rewriter.replaceAllUsesWith(op, initVal);
-      rewriter.eraseOp(op);
+      rewriter.replaceOp(op, initVal);
       return mlir::success();
     }
   } else if (const auto recordAttr =
@@ -2653,8 +2652,7 @@ mlir::LogicalResult CIRToLLVMVTableGetVPtrOpLowering::matchAndRewrite(
   // pointer to the vptr type. Since the LLVM dialect uses opaque pointers
   // we can just replace uses of this operation with the original pointer.
   mlir::Value srcVal = adaptor.getSrc();
-  rewriter.replaceAllUsesWith(op, srcVal);
-  rewriter.eraseOp(op);
+  rewriter.replaceOp (op, srcVal);
   return mlir::success();
 }
 

Copy link

github-actions bot commented Sep 8, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

This patch replaces all uses of replaceAllUseWith with replaceOp. This fixes a number of regressions post llvm#155244.
@mmha mmha force-pushed the fix-llvm-lowering-crash branch from 9cc2c12 to b3a93e2 Compare September 8, 2025 14:28
Copy link
Contributor

@andykaylor andykaylor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but it isn't clear to me why the crashes were occurring. I see from the description of #155244 that replaceAllUsesWith now has a delayed effect in some circumstances. Was the fact that we were erasing the replaced op causing a problem?

@mmha
Copy link
Contributor Author

mmha commented Sep 8, 2025

My understanding is that we are not supposed to erase an op that was replaced anymore. eraseOp calls replaceOp internally which lead to the double replacement assertion failure.

I also think in our case it doesn't really matter whether we use replaceOp and replaceAllUseWith

@mmha mmha merged commit 2d1ded2 into llvm:main Sep 8, 2025
9 checks passed
steven-studio pushed a commit to steven-studio/llvm-project that referenced this pull request Sep 11, 2025
This patch replaces all uses of `replaceAllUseWith` with `replaceOp`.
This fixes a number of regressions post llvm#155244.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants