Skip to content

Commit 415832b

Browse files
committed
[EarlyCSE] Rematerialize alignment assumption.
1 parent ef71226 commit 415832b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

llvm/lib/Transforms/Scalar/EarlyCSE.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "llvm/IR/Constants.h"
3232
#include "llvm/IR/Dominators.h"
3333
#include "llvm/IR/Function.h"
34+
#include "llvm/IR/IRBuilder.h"
3435
#include "llvm/IR/InstrTypes.h"
3536
#include "llvm/IR/Instruction.h"
3637
#include "llvm/IR/Instructions.h"
@@ -1588,6 +1589,14 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
15881589
if (InVal.IsLoad)
15891590
if (auto *I = dyn_cast<Instruction>(Op))
15901591
combineMetadataForCSE(I, &Inst, false);
1592+
if (auto *AlignMD = Inst.getMetadata(LLVMContext::MD_align)) {
1593+
auto *A = mdconst::extract<ConstantInt>(AlignMD->getOperand(0));
1594+
if (Op->getPointerAlignment(SQ.DL).value() % A->getZExtValue() != 0) {
1595+
IRBuilder B(&Inst);
1596+
B.CreateAlignmentAssumption(SQ.DL, Op, A);
1597+
}
1598+
}
1599+
15911600
if (!Inst.use_empty())
15921601
Inst.replaceAllUsesWith(Op);
15931602
salvageKnowledge(&Inst, &AC);

0 commit comments

Comments
 (0)