X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=test%2FOther%2Fconstant-fold-gep.ll;h=926bdbc1b464e1b311f49590de3011b6dc5b73b0;hb=8239daf7c83a65a189c352cce3191cdc3bbfe151;hp=2888b3d2b0d9d37d63b42f0ebb6b2ae0f2e7eebb;hpb=a84ffedafc102013a935817f30485a47d3dc2383;p=oota-llvm.git diff --git a/test/Other/constant-fold-gep.ll b/test/Other/constant-fold-gep.ll index 2888b3d2b0d..926bdbc1b46 100644 --- a/test/Other/constant-fold-gep.ll +++ b/test/Other/constant-fold-gep.ll @@ -21,10 +21,12 @@ ; PLAIN: %1 = type { double, float, double, double } ; PLAIN: %2 = type { i1, i1* } ; PLAIN: %3 = type { i64, i64 } +; PLAIN: %4 = type { i32, i32 } ; OPT: %0 = type { i1, double } ; OPT: %1 = type { double, float, double, double } ; OPT: %2 = type { i1, i1* } ; OPT: %3 = type { i64, i64 } +; OPT: %4 = type { i32, i32 } ; The automatic constant folder in opt does not have targetdata access, so ; it can't fold gep arithmetic, in general. However, the constant folder run @@ -110,9 +112,19 @@ ; TO: @N = constant i64* inttoptr (i64 8 to i64*) ; TO: @O = constant i64* inttoptr (i64 8 to i64*) -@M = constant i64* getelementptr (i64 *null, i32 1) -@N = constant i64* getelementptr ({ i64, i64 } *null, i32 0, i32 1) -@O = constant i64* getelementptr ([2 x i64] *null, i32 0, i32 1) +@M = constant i64* getelementptr (i64* null, i32 1) +@N = constant i64* getelementptr ({ i64, i64 }* null, i32 0, i32 1) +@O = constant i64* getelementptr ([2 x i64]* null, i32 0, i32 1) + +; Fold GEP of a GEP. Theoretically some of these cases could be folded +; without using targetdata, however that's not implemented yet. + +; PLAIN: @Z = global i32* getelementptr inbounds (i32* getelementptr inbounds ([3 x %4]* @ext, i64 0, i64 1, i32 0), i64 1) +; OPT: @Z = global i32* getelementptr (i32* getelementptr inbounds ([3 x %4]* @ext, i64 0, i64 1, i32 0), i64 1) +; TO: @Z = global i32* getelementptr inbounds ([3 x %0]* @ext, i64 0, i64 1, i32 1) + +@ext = external global [3 x { i32, i32 }] +@Z = global i32* getelementptr inbounds (i32* getelementptr inbounds ([3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1) ; Duplicate all of the above as function return values rather than ; global initializers. @@ -244,15 +256,15 @@ define i1* @hoo1() nounwind { ; PLAIN: ret i64 %t ; PLAIN: } ; PLAIN: define i64 @fg() nounwind { -; PLAIN: %t = bitcast i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64) +; PLAIN: %t = bitcast i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64) to i64 ; PLAIN: ret i64 %t ; PLAIN: } ; PLAIN: define i64 @fh() nounwind { -; PLAIN: %t = bitcast i64 ptrtoint (i1** getelementptr (i1** null, i32 1) to i64) +; PLAIN: %t = bitcast i64 ptrtoint (i1** getelementptr (i1** null, i32 1) to i64) to i64 ; PLAIN: ret i64 %t ; PLAIN: } ; PLAIN: define i64 @fi() nounwind { -; PLAIN: %t = bitcast i64 ptrtoint (i1** getelementptr (%2* null, i64 0, i32 1) to i64) +; PLAIN: %t = bitcast i64 ptrtoint (i1** getelementptr (%2* null, i64 0, i32 1) to i64) to i64 ; PLAIN: ret i64 %t ; PLAIN: } ; OPT: define i64 @fa() nounwind { @@ -328,13 +340,13 @@ define i1* @hoo1() nounwind { ; SCEV: %t = bitcast i64 1 to i64 ; SCEV: --> 1 ; SCEV: Classifying expressions for: @fg -; SCEV: %t = bitcast i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64) +; SCEV: %t = bitcast i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64) to i64 ; SCEV: --> alignof(double) ; SCEV: Classifying expressions for: @fh -; SCEV: %t = bitcast i64 ptrtoint (i1** getelementptr (i1** null, i32 1) to i64) +; SCEV: %t = bitcast i64 ptrtoint (i1** getelementptr (i1** null, i32 1) to i64) to i64 ; SCEV: --> sizeof(i1*) ; SCEV: Classifying expressions for: @fi -; SCEV: %t = bitcast i64 ptrtoint (i1** getelementptr (%2* null, i64 0, i32 1) to i64) +; SCEV: %t = bitcast i64 ptrtoint (i1** getelementptr (%2* null, i64 0, i32 1) to i64) to i64 ; SCEV: --> alignof(i1*) define i64 @fa() nounwind { @@ -415,14 +427,33 @@ define i64 @fi() nounwind { ; SCEV: --> sizeof(i64) define i64* @fM() nounwind { - %t = bitcast i64* getelementptr (i64 *null, i32 1) to i64* + %t = bitcast i64* getelementptr (i64* null, i32 1) to i64* ret i64* %t } define i64* @fN() nounwind { - %t = bitcast i64* getelementptr ({ i64, i64 } *null, i32 0, i32 1) to i64* + %t = bitcast i64* getelementptr ({ i64, i64 }* null, i32 0, i32 1) to i64* ret i64* %t } define i64* @fO() nounwind { - %t = bitcast i64* getelementptr ([2 x i64] *null, i32 0, i32 1) to i64* + %t = bitcast i64* getelementptr ([2 x i64]* null, i32 0, i32 1) to i64* ret i64* %t } + +; PLAIN: define i32* @fZ() nounwind { +; PLAIN: %t = bitcast i32* getelementptr inbounds (i32* getelementptr inbounds ([3 x %4]* @ext, i64 0, i64 1, i32 0), i64 1) to i32* +; PLAIN: ret i32* %t +; PLAIN: } +; OPT: define i32* @fZ() nounwind { +; OPT: ret i32* getelementptr inbounds (i32* getelementptr inbounds ([3 x %4]* @ext, i64 0, i64 1, i32 0), i64 1) +; OPT: } +; TO: define i32* @fZ() nounwind { +; TO: ret i32* getelementptr inbounds ([3 x %0]* @ext, i64 0, i64 1, i32 1) +; TO: } +; SCEV: Classifying expressions for: @fZ +; SCEV: %t = bitcast i32* getelementptr inbounds (i32* getelementptr inbounds ([3 x %4]* @ext, i64 0, i64 1, i32 0), i64 1) to i32* +; SCEV: --> ((3 * sizeof(i32)) + @ext) + +define i32* @fZ() nounwind { + %t = bitcast i32* getelementptr inbounds (i32* getelementptr inbounds ([3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1) to i32* + ret i32* %t +}