OSDN Git Service

[Attributor][FIX] Store alignment only holds for the pointer value
authorJohannes Doerfert <johannes@jdoerfert.de>
Fri, 10 Jan 2020 18:13:10 +0000 (12:13 -0600)
committerJohannes Doerfert <johannes@jdoerfert.de>
Fri, 24 Jan 2020 00:13:52 +0000 (18:13 -0600)
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
llvm/test/Transforms/Attributor/align.ll

index baa1cb1..5eb21a0 100644 (file)
@@ -3420,9 +3420,10 @@ static unsigned int getKnownAlignForUse(Attributor &A,
   }
 
   const Value *UseV = U->get();
-  if (auto *SI = dyn_cast<StoreInst>(I))
-    Alignment = SI->getAlignment();
-  else if (auto *LI = dyn_cast<LoadInst>(I))
+  if (auto *SI = dyn_cast<StoreInst>(I)) {
+    if (SI->getPointerOperand() == UseV)
+      Alignment = SI->getAlignment();
+  } else if (auto *LI = dyn_cast<LoadInst>(I))
     Alignment = LI->getAlignment();
 
   if (Alignment <= 1)
index e47141c..d961a18 100644 (file)
@@ -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" }