[llvm-commits] [llvm] r40649 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/known_align.ll
Lauro Ramos Venancio
lauro.venancio at gmail.com
Tue Jul 31 13:13:21 PDT 2007
Author: laurov
Date: Tue Jul 31 15:13:21 2007
New Revision: 40649
URL: http://llvm.org/viewvc/llvm-project?rev=40649&view=rev
Log:
Fix a bug in GetKnownAlignment of packed structs.
Added:
llvm/trunk/test/Transforms/InstCombine/known_align.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=40649&r1=40648&r2=40649&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Tue Jul 31 15:13:21 2007
@@ -7533,11 +7533,13 @@
const Type *BasePtrTy = GEPI->getOperand(0)->getType();
const PointerType *PtrTy = cast<PointerType>(BasePtrTy);
- if (TD->getABITypeAlignment(PtrTy->getElementType())
- <= BaseAlignment) {
+ unsigned Align = TD->getABITypeAlignment(PtrTy->getElementType());
+ if (Align <= BaseAlignment) {
const Type *GEPTy = GEPI->getType();
const PointerType *GEPPtrTy = cast<PointerType>(GEPTy);
- return TD->getABITypeAlignment(GEPPtrTy->getElementType());
+ Align = std::min(Align, (unsigned)
+ TD->getABITypeAlignment(GEPPtrTy->getElementType()));
+ return Align;
}
return 0;
}
Added: llvm/trunk/test/Transforms/InstCombine/known_align.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/known_align.ll?rev=40649&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/known_align.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/known_align.ll Tue Jul 31 15:13:21 2007
@@ -0,0 +1,27 @@
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep {align 1}
+; END.
+
+ %struct.p = type <{ i8, i32 }>
+ at t = global %struct.p <{ i8 1, i32 10 }> ; <%struct.p*> [#uses=1]
+ at u = weak global %struct.p zeroinitializer ; <%struct.p*> [#uses=1]
+
+define i32 @main() {
+entry:
+ %retval = alloca i32, align 4 ; <i32*> [#uses=2]
+ %tmp = alloca i32, align 4 ; <i32*> [#uses=2]
+ %tmp1 = alloca i32, align 4 ; <i32*> [#uses=3]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %tmp3 = load i32* getelementptr (%struct.p* @t, i32 0, i32 1), align 1 ; <i32> [#uses=1]
+ store i32 %tmp3, i32* %tmp1, align 4
+ %tmp5 = load i32* %tmp1, align 4 ; <i32> [#uses=1]
+ store i32 %tmp5, i32* getelementptr (%struct.p* @u, i32 0, i32 1), align 1
+ %tmp6 = load i32* %tmp1, align 4 ; <i32> [#uses=1]
+ store i32 %tmp6, i32* %tmp, align 4
+ %tmp7 = load i32* %tmp, align 4 ; <i32> [#uses=1]
+ store i32 %tmp7, i32* %retval, align 4
+ br label %return
+
+return: ; preds = %entry
+ %retval8 = load i32* %retval ; <i32> [#uses=1]
+ ret i32 %retval8
+}
More information about the llvm-commits
mailing list