From 30ae859c696748e1314788367226e4c65669f526 Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Fri, 10 Jan 2020 12:13:10 -0600 Subject: [PATCH] [Attributor][FIX] Store alignment only holds for the pointer value We accidentally used the store alignment for the value operand as well, which is incorrect and crashed the SPASS application in the test suite. --- llvm/lib/Transforms/IPO/Attributor.cpp | 7 ++++--- llvm/test/Transforms/Attributor/align.ll | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index baa1cb125d7..5eb21a0691b 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -3420,9 +3420,10 @@ static unsigned int getKnownAlignForUse(Attributor &A, } const Value *UseV = U->get(); - if (auto *SI = dyn_cast(I)) - Alignment = SI->getAlignment(); - else if (auto *LI = dyn_cast(I)) + if (auto *SI = dyn_cast(I)) { + if (SI->getPointerOperand() == UseV) + Alignment = SI->getAlignment(); + } else if (auto *LI = dyn_cast(I)) Alignment = LI->getAlignment(); if (Alignment <= 1) diff --git a/llvm/test/Transforms/Attributor/align.ll b/llvm/test/Transforms/Attributor/align.ll index e47141ca16a..d961a18f642 100644 --- a/llvm/test/Transforms/Attributor/align.ll +++ b/llvm/test/Transforms/Attributor/align.ll @@ -501,6 +501,13 @@ define i64* @int2ptr(i64 %i) { ret i64* %i2p } +; Use the store alignment only for the pointer operand. +define void @aligned_store(i8* %Value, i8** %Ptr) { +; ATTRIBUTOR: define void @aligned_store(i8* nofree writeonly %Value, i8** nocapture nofree nonnull writeonly align 32 dereferenceable(8) %Ptr) + store i8* %Value, i8** %Ptr, align 32 + ret void +} + attributes #0 = { nounwind uwtable noinline } attributes #1 = { uwtable noinline } attributes #2 = { "null-pointer-is-valid"="true" } -- 2.11.0