[PATCH] D66567: [Attributor] Manifest alignment in load and store instructions
Johannes Doerfert via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 21 17:05:43 PDT 2019
jdoerfert created this revision.
jdoerfert added reviewers: uenoku, sstefan1, lebedev.ri.
Herald added subscribers: bollu, hiraditya.
Herald added a project: LLVM.
We can now manifest alignment information in load/store instructions if
the pointer is known to have a better alignment.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D66567
Files:
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/test/Transforms/FunctionAttrs/align.ll
Index: llvm/test/Transforms/FunctionAttrs/align.ll
===================================================================
--- llvm/test/Transforms/FunctionAttrs/align.ll
+++ llvm/test/Transforms/FunctionAttrs/align.ll
@@ -171,6 +171,28 @@
ret void
}
+; ATTRIBUTOR: define align 32 i32* @test10(i32* align 32 %p)
+define i32* @test10(i32* align 32 %p) {
+; ATTRIBUTOR: %l = load i32, i32* %p, align 32
+ %l = load i32, i32* %p
+ %c = icmp eq i32 %l, 0
+ br i1 %c, label %t, label %f
+t:
+ %r = call i32* @test10(i32* %p)
+; FIXME: This will work with an upcoming patch
+; store i32 1, i32* %r, align 32
+ store i32 1, i32* %r
+ %g0 = getelementptr i32, i32* %p, i32 8
+ br label %e
+f:
+ %g1 = getelementptr i32, i32* %p, i32 -8
+; ATTRIBUTOR: store i32 -1, i32* %g1, align 32
+ store i32 -1, i32* %g1
+ br label %e
+e:
+ %phi = phi i32* [%g0, %t], [%g1, %f]
+ ret i32* %phi
+}
attributes #0 = { nounwind uwtable noinline }
attributes #1 = { uwtable noinline }
Index: llvm/lib/Transforms/IPO/Attributor.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Attributor.cpp
+++ llvm/lib/Transforms/IPO/Attributor.cpp
@@ -2174,6 +2174,31 @@
struct AAAlignFloating : AAAlignImpl {
AAAlignFloating(const IRPosition &IRP) : AAAlignImpl(IRP) {}
+ /// See AbstractAttribute::manifest(...).
+ ChangeStatus manifest(Attributor &A) override {
+ ChangeStatus Changed = ChangeStatus::UNCHANGED;
+
+ // Check for users that allow alignment annotations.
+ Value &AnchorVal = getIRPosition().getAnchorValue();
+ for (const Use &U : AnchorVal.uses()) {
+ if (auto *SI = dyn_cast<StoreInst>(U.getUser())) {
+ if (SI->getPointerOperand() == &AnchorVal)
+ if (SI->getAlignment() < getAssumedAlign()) {
+ SI->setAlignment(getAssumedAlign());
+ Changed = ChangeStatus::CHANGED;
+ }
+ } else if (auto *LI = dyn_cast<LoadInst>(U.getUser())) {
+ if (LI->getPointerOperand() == &AnchorVal)
+ if (LI->getAlignment() < getAssumedAlign()) {
+ LI->setAlignment(getAssumedAlign());
+ Changed = ChangeStatus::CHANGED;
+ }
+ }
+ }
+
+ return AAAlignImpl::manifest(A) | Changed;
+ }
+
/// See AbstractAttribute::updateImpl(...).
ChangeStatus updateImpl(Attributor &A) override {
const DataLayout &DL = A.getDataLayout();
@@ -2231,6 +2256,11 @@
struct AAAlignCallSiteArgument final : AAAlignFloating {
AAAlignCallSiteArgument(const IRPosition &IRP) : AAAlignFloating(IRP) {}
+ /// See AbstractAttribute::manifest(...).
+ ChangeStatus manifest(Attributor &A) override {
+ return AAAlignImpl::manifest(A);
+ }
+
/// See AbstractAttribute::trackStatistics()
void trackStatistics() const override { STATS_DECLTRACK_CSARG_ATTR(aligned) }
};
@@ -2706,6 +2736,18 @@
"New call site/base instruction type needs to be known int the "
"attributor.");
break;
+ case Instruction::Load:
+ // The alignment of a pointer is interesting for stores.
+ checkAndRegisterAA<AAAlignFloating>(
+ IRPosition::value(*cast<LoadInst>(I).getPointerOperand()), *this,
+ Whitelist);
+ break;
+ case Instruction::Store:
+ // The alignment of a pointer is interesting for stores.
+ checkAndRegisterAA<AAAlignFloating>(
+ IRPosition::value(*cast<StoreInst>(I).getPointerOperand()), *this,
+ Whitelist);
+ break;
case Instruction::Call:
case Instruction::CallBr:
case Instruction::Invoke:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66567.216526.patch
Type: text/x-patch
Size: 3572 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190822/77047529/attachment.bin>
More information about the llvm-commits
mailing list