[llvm] r202229 - [SROA] Use NewOffsetBegin in the unsplit case for memset merely for

Chandler Carruth chandlerc at gmail.com
Tue Feb 25 20:45:25 PST 2014


Author: chandlerc
Date: Tue Feb 25 22:45:24 2014
New Revision: 202229

URL: http://llvm.org/viewvc/llvm-project?rev=202229&view=rev
Log:
[SROA] Use NewOffsetBegin in the unsplit case for memset merely for
consistency with memcpy rewriting, and fix a latent bug in the alignment
management for memset.

The alignment issue is that getAdjustedAllocaPtr is computing the
*relative* offset into the new alloca, but the alignment isn't being set
to the relative offset, it was using the the absolute offset which is
into the old alloca.

I don't think its possible to write a test case that actually reaches
this code where the resulting alignment would be observably different,
but the intent was clearly to use the relative offset within the new
alloca.

Modified:
    llvm/trunk/lib/Transforms/Scalar/SROA.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/SROA.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=202229&r1=202228&r2=202229&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SROA.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp Tue Feb 25 22:45:24 2014
@@ -2393,10 +2393,11 @@ private:
     // pointer to the new alloca.
     if (!isa<Constant>(II.getLength())) {
       assert(!IsSplit);
-      assert(BeginOffset >= NewAllocaBeginOffset);
-      II.setDest(getAdjustedAllocaPtr(IRB, BeginOffset, OldPtr->getType()));
+      assert(NewBeginOffset == BeginOffset);
+      II.setDest(getAdjustedAllocaPtr(IRB, NewBeginOffset, OldPtr->getType()));
       Type *CstTy = II.getAlignmentCst()->getType();
-      II.setAlignment(ConstantInt::get(CstTy, getOffsetAlign(BeginOffset)));
+      II.setAlignment(ConstantInt::get(
+          CstTy, getOffsetAlign(NewBeginOffset - NewAllocaBeginOffset)));
 
       deleteIfTriviallyDead(OldPtr);
       return false;





More information about the llvm-commits mailing list