[llvm] r276601 - [GVNHoist] Properly merge alignments when hoisting
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 24 19:21:23 PDT 2016
Author: majnemer
Date: Sun Jul 24 21:21:23 2016
New Revision: 276601
URL: http://llvm.org/viewvc/llvm-project?rev=276601&view=rev
Log:
[GVNHoist] Properly merge alignments when hoisting
If we two loads of two different alignments, we must use the minimum of
the two alignments when hoisting. Same deal for stores.
For allocas, use the maximum of the two allocas.
Modified:
llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp
llvm/trunk/test/Transforms/GVN/hoist.ll
Modified: llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp?rev=276601&r1=276600&r2=276601&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp Sun Jul 24 21:21:23 2016
@@ -628,7 +628,6 @@ public:
cast<Instruction>(cast<StoreInst>(OtherInst)->getValueOperand());
ClonedVal->intersectOptionalDataWith(OtherVal);
}
- ClonedVal->clearSubclassOptionalData();
Repl->replaceUsesOfWith(Val, ClonedVal);
}
@@ -685,12 +684,23 @@ public:
for (Instruction *I : InstructionsToHoist)
if (I != Repl) {
++NR;
- if (isa<LoadInst>(Repl))
+ if (auto *ReplacementLoad = dyn_cast<LoadInst>(Repl)) {
+ ReplacementLoad->setAlignment(
+ std::min(ReplacementLoad->getAlignment(),
+ cast<LoadInst>(I)->getAlignment()));
++NumLoadsRemoved;
- else if (isa<StoreInst>(Repl))
+ } else if (auto *ReplacementStore = dyn_cast<StoreInst>(Repl)) {
+ ReplacementStore->setAlignment(
+ std::min(ReplacementStore->getAlignment(),
+ cast<StoreInst>(I)->getAlignment()));
++NumStoresRemoved;
- else if (isa<CallInst>(Repl))
+ } else if (auto *ReplacementAlloca = dyn_cast<AllocaInst>(Repl)) {
+ ReplacementAlloca->setAlignment(
+ std::max(ReplacementAlloca->getAlignment(),
+ cast<AllocaInst>(I)->getAlignment()));
+ } else if (isa<CallInst>(Repl)) {
++NumCallsRemoved;
+ }
Repl->intersectOptionalDataWith(I);
I->replaceAllUsesWith(Repl);
I->eraseFromParent();
Modified: llvm/trunk/test/Transforms/GVN/hoist.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/hoist.ll?rev=276601&r1=276600&r2=276601&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GVN/hoist.ll (original)
+++ llvm/trunk/test/Transforms/GVN/hoist.ll Sun Jul 24 21:21:23 2016
@@ -689,3 +689,24 @@ if.else:
if.end: ; preds = %if.else, %if.then
ret void
}
+
+define i32 @mergeAlignments(i1 %b, i32* %y) {
+entry:
+ br i1 %b, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ %l1 = load i32, i32* %y, align 4
+ br label %return
+
+if.end: ; preds = %entry
+ %l2 = load i32, i32* %y, align 1
+ br label %return
+
+return: ; preds = %if.end, %if.then
+ %retval.0 = phi i32 [ %l1, %if.then ], [ %l2, %if.end ]
+ ret i32 %retval.0
+}
+; CHECK-LABEL: define i32 @mergeAlignments(
+; CHECK: %[[load:.*]] = load i32, i32* %y, align 1
+; CHECK: %[[phi:.*]] = phi i32 [ %[[load]], %{{.*}} ], [ %[[load]], %{{.*}} ]
+; CHECK: i32 %[[phi]]
More information about the llvm-commits
mailing list