[llvm-commits] [patch] Use correct alignment when merging zero sized arrays in instruction combine

Duncan Sands baldrick at free.fr
Mon Sep 17 10:47:53 PDT 2012


Hi Richard,

On 17/09/12 17:50, Richard Osborne wrote:
> I noticed that when merging zero sized allocas instruction combine ignores the
> alignment set on the alloca instruction. This patch fixes this. OK to commit?

thanks for spotting this.

+/// getPointeeAlignment - Compute the minimum alignment of the given alloca
+/// instruction.

^ The function name and text in the comment don't match the actual function:

+static unsigned getAllocaAlignment(AllocaInst &AI, TargetData &TD) {
+  return std::max(TD.getPrefTypeAlignment(AI.getAllocatedType()),
+                  AI.getAlignment());
+}

While this logic is consistent with what was there before, I'm not sure it
is really right.  Consider a few lines before:

     if (AI.getAlignment() == 0)
       AI.setAlignment(TD->getPrefTypeAlignment(AI.getAllocatedType()));

So if the alloca was explicitly marked "align 1" then its alignment doesn't
get bumped up.  However in the merging we do bump it up.  To be consistent
the logic should probably be the following:
   if EntryAI has alignment 0, then give it its preferred alignment;
   give EntryAI the maximum of EntryAI.getAlignment() and AI.getAlignment()
(the last of these two is known non-zero already due to the code I mentioned
above).

Ciao, Duncan.



More information about the llvm-commits mailing list