diff options
author | Pierre van Houtryve <pierre.vanhoutryve@amd.com> | 2024-04-24 08:52:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-24 08:52:25 +0200 |
commit | cf328ff96daf5e676fb51ac86e550af7fd689fec (patch) | |
tree | 5ddf3b93433e9fe04a349663d1f1f50d0721f28b /llvm/lib/Transforms/Utils/SimplifyCFG.cpp | |
parent | 805d5637a0d50caa073f435b55940c1338aae0fc (diff) | |
download | llvm-cf328ff96daf5e676fb51ac86e550af7fd689fec.zip llvm-cf328ff96daf5e676fb51ac86e550af7fd689fec.tar.gz llvm-cf328ff96daf5e676fb51ac86e550af7fd689fec.tar.bz2 |
[IR] Memory Model Relaxation Annotations (#78569)
Implements the core/target-agnostic components of Memory Model
Relaxation Annotations.
RFC:
https://discourse.llvm.org/t/rfc-mmras-memory-model-relaxation-annotations/76361/5
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 0826d74..3eda669 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -51,6 +51,7 @@ #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/MDBuilder.h" +#include "llvm/IR/MemoryModelRelaxationAnnotations.h" #include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" #include "llvm/IR/NoFolder.h" @@ -1677,7 +1678,8 @@ bool SimplifyCFGOpt::hoistCommonCodeFromSuccessors(BasicBlock *BB, for (auto &SuccIter : OtherSuccIterRange) { Instruction *I2 = &*SuccIter; HasTerminator |= I2->isTerminator(); - if (AllInstsAreIdentical && !I1->isIdenticalToWhenDefined(I2)) + if (AllInstsAreIdentical && (!I1->isIdenticalToWhenDefined(I2) || + MMRAMetadata(*I1) != MMRAMetadata(*I2))) AllInstsAreIdentical = false; } @@ -1964,6 +1966,7 @@ static bool canSinkInstructions( } const Instruction *I0 = Insts.front(); + const auto I0MMRA = MMRAMetadata(*I0); for (auto *I : Insts) { if (!I->isSameOperationAs(I0)) return false; @@ -1975,6 +1978,11 @@ static bool canSinkInstructions( return false; if (isa<LoadInst>(I) && I->getOperand(0)->isSwiftError()) return false; + + // Treat MMRAs conservatively. This pass can be quite aggressive and + // could drop a lot of MMRAs otherwise. + if (MMRAMetadata(*I) != I0MMRA) + return false; } // All instructions in Insts are known to be the same opcode. If they have a |