diff options
author | Nikita Popov <npopov@redhat.com> | 2024-04-23 12:36:35 +0900 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2024-04-23 12:39:35 +0900 |
commit | 883887493c882d656d5da100ee637a348e81357c (patch) | |
tree | e52870e2f863318da87d1ba60e382597293557e1 /llvm/lib/Transforms/Utils/SimplifyCFG.cpp | |
parent | b64e483785bfef5ec4977988543ed5cfaf62f306 (diff) | |
download | llvm-883887493c882d656d5da100ee637a348e81357c.zip llvm-883887493c882d656d5da100ee637a348e81357c.tar.gz llvm-883887493c882d656d5da100ee637a348e81357c.tar.bz2 |
[SimplifyCFG] Check alignment when speculating stores
When speculating a store based on a preceding load/store, we need
to ensure that the speculated store does not have a higher
alignment (which might only be guaranteed by the branch condition).
There are various ways in which this could be strengthened (we
could get or enforce the alignment), but for now just do the
simple check against the preceding load/store.
Fixes https://github.com/llvm/llvm-project/issues/89672.
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index da3eb22..0826d74 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -2888,7 +2888,8 @@ static Value *isSafeToSpeculateStore(Instruction *I, BasicBlock *BrBB, // simple, to avoid introducing a spurious non-atomic write after an // atomic write. if (SI->getPointerOperand() == StorePtr && - SI->getValueOperand()->getType() == StoreTy && SI->isSimple()) + SI->getValueOperand()->getType() == StoreTy && SI->isSimple() && + SI->getAlign() >= StoreToHoist->getAlign()) // Found the previous store, return its value operand. return SI->getValueOperand(); return nullptr; // Unknown store. @@ -2896,7 +2897,7 @@ static Value *isSafeToSpeculateStore(Instruction *I, BasicBlock *BrBB, if (auto *LI = dyn_cast<LoadInst>(&CurI)) { if (LI->getPointerOperand() == StorePtr && LI->getType() == StoreTy && - LI->isSimple()) { + LI->isSimple() && LI->getAlign() >= StoreToHoist->getAlign()) { // Local objects (created by an `alloca` instruction) are always // writable, so once we are past a read from a location it is valid to // also write to that same location. |