Use clone to keep the metadata
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I think this is right, but I'm not very confident about it. The problem is that mergeicmps can reorder loads, but I think these isolated comparisons will not get reordered before other ones (only possibly after), so I think it's fine. But maybe I just didn't manage to construct the right test case.
llvm/lib/Transforms/Scalar/MergeICmps.cpp | ||
---|---|---|
646 | Maybe it would be better to clone the instructions, similar to the GEPs above? |
llvm/lib/Transforms/Scalar/MergeICmps.cpp | ||
---|---|---|
646 | Thanks for your suggestion. @@ -639,10 +640,9 @@ static BasicBlock *mergeComparisons(ArrayRef<BCECmpBlock> Comparisons, if (Comparisons.size() == 1) { LLVM_DEBUG(dbgs() << "Only one comparison, updating branches\n"); - Value *const LhsLoad = - Builder.CreateLoad(FirstCmp.Lhs().LoadI->getType(), Lhs); - Value *const RhsLoad = - Builder.CreateLoad(FirstCmp.Rhs().LoadI->getType(), Rhs); + Instruction *const LhsLoad = Builder.Insert(FirstCmp.Lhs().LoadI->clone()); + Instruction *const RhsLoad = Builder.Insert(FirstCmp.Rhs().LoadI->clone()); |
hi @nikic
If you don't object, I still use the current solution with **new CreateLoad** temporarily?
llvm/lib/Transforms/Scalar/MergeICmps.cpp | ||
---|---|---|
646 | I use replaceUsesOfWith to update the PointerOperand, then clone according your comment works fine. |
Maybe it would be better to clone the instructions, similar to the GEPs above?