diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -1259,7 +1259,9 @@ // Otherwise compute the distance with SCEV between the base pointers. const SCEV *PtrSCEVA = SE.getSCEV(PtrA); const SCEV *PtrSCEVB = SE.getSCEV(PtrB); - const SCEV *X = SE.getAddExpr(PtrSCEVA, BaseDelta); + const SCEV *X = SE.getAddExpr( + PtrSCEVA, SE.getTruncateOrSignExtend( + BaseDelta, SE.getEffectiveSCEVType(PtrSCEVA->getType()))); return X == PtrSCEVB; } diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -3568,14 +3568,12 @@ /// return true. uint64_t ScalarEvolution::getTypeSizeInBits(Type *Ty) const { assert(isSCEVable(Ty) && "Type is not SCEVable!"); - if (Ty->isPointerTy()) - return getDataLayout().getIndexTypeSizeInBits(Ty); - return getDataLayout().getTypeSizeInBits(Ty); + return getDataLayout().getTypeSizeInBits(getEffectiveSCEVType(Ty)); } /// Return a type with the same bitwidth as the given type and which represents /// how SCEV will treat the given type, for which isSCEVable must return -/// true. For pointer types, this is the pointer index sized integer type. +/// true. For pointer types, this is the pointer-sized integer type. Type *ScalarEvolution::getEffectiveSCEVType(Type *Ty) const { assert(isSCEVable(Ty) && "Type is not SCEVable!"); @@ -3584,7 +3582,7 @@ // The only other support type is pointer. assert(Ty->isPointerTy() && "Unexpected non-pointer non-integer type!"); - return getDataLayout().getIndexType(Ty); + return getDataLayout().getIntPtrType(Ty); } Type *ScalarEvolution::getWiderType(Type *T1, Type *T2) const { diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp --- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -943,7 +943,7 @@ SCEVExpanderCleaner ExpCleaner(Expander, *DT); Type *DestInt8PtrTy = Builder.getInt8PtrTy(DestAS); - Type *IntIdxTy = DL->getIndexType(DestPtr->getType()); + Type *IntIdxTy = SE->getEffectiveSCEVType(DestPtr->getType()); bool Changed = false; const SCEV *Start = Ev->getStart(); @@ -1086,7 +1086,7 @@ bool Changed = false; const SCEV *StrStart = StoreEv->getStart(); unsigned StrAS = SI->getPointerAddressSpace(); - Type *IntIdxTy = Builder.getIntNTy(DL->getIndexSizeInBits(StrAS)); + Type *IntIdxTy = Builder.getIntNTy(DL->getPointerSizeInBits(StrAS)); // Handle negative strided loops. if (NegStride) diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -438,7 +438,7 @@ // without the other. SplitAddRecs(Ops, Ty, SE); - Type *IntIdxTy = DL.getIndexType(PTy); + Type *IntIdxTy = DL.getIntPtrType(PTy); // Descend down the pointer's type and attempt to convert the other // operands into GEP indices, at each level. The first index in a GEP diff --git a/llvm/test/Analysis/ScalarEvolution/ptrtoint-constantexpr-loop.ll b/llvm/test/Analysis/ScalarEvolution/ptrtoint-constantexpr-loop.ll --- a/llvm/test/Analysis/ScalarEvolution/ptrtoint-constantexpr-loop.ll +++ b/llvm/test/Analysis/ScalarEvolution/ptrtoint-constantexpr-loop.ll @@ -13,73 +13,39 @@ declare void @use16(i16) define hidden i32* @trunc_ptr_to_i64(i8* %arg, i32* %arg10) { -; PTR64_IDX64-LABEL: 'trunc_ptr_to_i64' -; PTR64_IDX64-NEXT: Classifying expressions for: @trunc_ptr_to_i64 -; PTR64_IDX64-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] -; PTR64_IDX64-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR64_IDX64-NEXT: %tmp12 = getelementptr i8, i8* %arg, i64 ptrtoint ([0 x i8]* @global to i64) -; PTR64_IDX64-NEXT: --> (ptrtoint ([0 x i8]* @global to i64) + %arg) U: full-set S: full-set Exits: (ptrtoint ([0 x i8]* @global to i64) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR64_IDX64-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* -; PTR64_IDX64-NEXT: --> (ptrtoint ([0 x i8]* @global to i64) + %arg) U: full-set S: full-set Exits: (ptrtoint ([0 x i8]* @global to i64) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR64_IDX64-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 -; PTR64_IDX64-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } -; PTR64_IDX64-NEXT: %tmp18 = add i32 %tmp, 2 -; PTR64_IDX64-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR64_IDX64-NEXT: Determining loop execution counts for: @trunc_ptr_to_i64 -; PTR64_IDX64-NEXT: Loop %bb11: Unpredictable backedge-taken count. -; PTR64_IDX64-NEXT: Loop %bb11: Unpredictable max backedge-taken count. -; PTR64_IDX64-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. +; X64-LABEL: 'trunc_ptr_to_i64' +; X64-NEXT: Classifying expressions for: @trunc_ptr_to_i64 +; X64-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] +; X64-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } +; X64-NEXT: %tmp12 = getelementptr i8, i8* %arg, i64 ptrtoint ([0 x i8]* @global to i64) +; X64-NEXT: --> (ptrtoint ([0 x i8]* @global to i64) + %arg) U: full-set S: full-set Exits: (ptrtoint ([0 x i8]* @global to i64) + %arg) LoopDispositions: { %bb11: Invariant } +; X64-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* +; X64-NEXT: --> (ptrtoint ([0 x i8]* @global to i64) + %arg) U: full-set S: full-set Exits: (ptrtoint ([0 x i8]* @global to i64) + %arg) LoopDispositions: { %bb11: Invariant } +; X64-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 +; X64-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } +; X64-NEXT: %tmp18 = add i32 %tmp, 2 +; X64-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } +; X64-NEXT: Determining loop execution counts for: @trunc_ptr_to_i64 +; X64-NEXT: Loop %bb11: Unpredictable backedge-taken count. +; X64-NEXT: Loop %bb11: Unpredictable max backedge-taken count. +; X64-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. ; -; PTR64_IDX32-LABEL: 'trunc_ptr_to_i64' -; PTR64_IDX32-NEXT: Classifying expressions for: @trunc_ptr_to_i64 -; PTR64_IDX32-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] -; PTR64_IDX32-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR64_IDX32-NEXT: %tmp12 = getelementptr i8, i8* %arg, i64 ptrtoint ([0 x i8]* @global to i64) -; PTR64_IDX32-NEXT: --> ((trunc i64 ptrtoint ([0 x i8]* @global to i64) to i32) + %arg) U: full-set S: full-set Exits: ((trunc i64 ptrtoint ([0 x i8]* @global to i64) to i32) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR64_IDX32-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* -; PTR64_IDX32-NEXT: --> ((trunc i64 ptrtoint ([0 x i8]* @global to i64) to i32) + %arg) U: full-set S: full-set Exits: ((trunc i64 ptrtoint ([0 x i8]* @global to i64) to i32) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR64_IDX32-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 -; PTR64_IDX32-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } -; PTR64_IDX32-NEXT: %tmp18 = add i32 %tmp, 2 -; PTR64_IDX32-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR64_IDX32-NEXT: Determining loop execution counts for: @trunc_ptr_to_i64 -; PTR64_IDX32-NEXT: Loop %bb11: Unpredictable backedge-taken count. -; PTR64_IDX32-NEXT: Loop %bb11: Unpredictable max backedge-taken count. -; PTR64_IDX32-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. -; -; PTR16_IDX16-LABEL: 'trunc_ptr_to_i64' -; PTR16_IDX16-NEXT: Classifying expressions for: @trunc_ptr_to_i64 -; PTR16_IDX16-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] -; PTR16_IDX16-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR16_IDX16-NEXT: %tmp12 = getelementptr i8, i8* %arg, i64 ptrtoint ([0 x i8]* @global to i64) -; PTR16_IDX16-NEXT: --> ((trunc i64 ptrtoint ([0 x i8]* @global to i64) to i16) + %arg) U: full-set S: full-set Exits: ((trunc i64 ptrtoint ([0 x i8]* @global to i64) to i16) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR16_IDX16-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* -; PTR16_IDX16-NEXT: --> ((trunc i64 ptrtoint ([0 x i8]* @global to i64) to i16) + %arg) U: full-set S: full-set Exits: ((trunc i64 ptrtoint ([0 x i8]* @global to i64) to i16) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR16_IDX16-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 -; PTR16_IDX16-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } -; PTR16_IDX16-NEXT: %tmp18 = add i32 %tmp, 2 -; PTR16_IDX16-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR16_IDX16-NEXT: Determining loop execution counts for: @trunc_ptr_to_i64 -; PTR16_IDX16-NEXT: Loop %bb11: Unpredictable backedge-taken count. -; PTR16_IDX16-NEXT: Loop %bb11: Unpredictable max backedge-taken count. -; PTR16_IDX16-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. -; -; PTR16_IDX32-LABEL: 'trunc_ptr_to_i64' -; PTR16_IDX32-NEXT: Classifying expressions for: @trunc_ptr_to_i64 -; PTR16_IDX32-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] -; PTR16_IDX32-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR16_IDX32-NEXT: %tmp12 = getelementptr i8, i8* %arg, i64 ptrtoint ([0 x i8]* @global to i64) -; PTR16_IDX32-NEXT: --> ((trunc i64 ptrtoint ([0 x i8]* @global to i64) to i32) + %arg) U: [0,131071) S: full-set Exits: ((trunc i64 ptrtoint ([0 x i8]* @global to i64) to i32) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR16_IDX32-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* -; PTR16_IDX32-NEXT: --> ((trunc i64 ptrtoint ([0 x i8]* @global to i64) to i32) + %arg) U: [0,131071) S: full-set Exits: ((trunc i64 ptrtoint ([0 x i8]* @global to i64) to i32) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR16_IDX32-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 -; PTR16_IDX32-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } -; PTR16_IDX32-NEXT: %tmp18 = add i32 %tmp, 2 -; PTR16_IDX32-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR16_IDX32-NEXT: Determining loop execution counts for: @trunc_ptr_to_i64 -; PTR16_IDX32-NEXT: Loop %bb11: Unpredictable backedge-taken count. -; PTR16_IDX32-NEXT: Loop %bb11: Unpredictable max backedge-taken count. -; PTR16_IDX32-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. +; X32-LABEL: 'trunc_ptr_to_i64' +; X32-NEXT: Classifying expressions for: @trunc_ptr_to_i64 +; X32-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] +; X32-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } +; X32-NEXT: %tmp12 = getelementptr i8, i8* %arg, i64 ptrtoint ([0 x i8]* @global to i64) +; X32-NEXT: --> ((trunc i64 ptrtoint ([0 x i8]* @global to i64) to i16) + %arg) U: full-set S: full-set Exits: ((trunc i64 ptrtoint ([0 x i8]* @global to i64) to i16) + %arg) LoopDispositions: { %bb11: Invariant } +; X32-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* +; X32-NEXT: --> ((trunc i64 ptrtoint ([0 x i8]* @global to i64) to i16) + %arg) U: full-set S: full-set Exits: ((trunc i64 ptrtoint ([0 x i8]* @global to i64) to i16) + %arg) LoopDispositions: { %bb11: Invariant } +; X32-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 +; X32-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } +; X32-NEXT: %tmp18 = add i32 %tmp, 2 +; X32-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } +; X32-NEXT: Determining loop execution counts for: @trunc_ptr_to_i64 +; X32-NEXT: Loop %bb11: Unpredictable backedge-taken count. +; X32-NEXT: Loop %bb11: Unpredictable max backedge-taken count. +; X32-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. ; bb: br label %bb11 @@ -100,73 +66,39 @@ br label %bb11 } define hidden i32* @trunc_ptr_to_i32(i8* %arg, i32* %arg10) { -; PTR64_IDX64-LABEL: 'trunc_ptr_to_i32' -; PTR64_IDX64-NEXT: Classifying expressions for: @trunc_ptr_to_i32 -; PTR64_IDX64-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] -; PTR64_IDX64-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR64_IDX64-NEXT: %tmp12 = getelementptr i8, i8* %arg, i32 ptrtoint ([0 x i8]* @global to i32) -; PTR64_IDX64-NEXT: --> ((sext i32 ptrtoint ([0 x i8]* @global to i32) to i64) + %arg) U: full-set S: full-set Exits: ((sext i32 ptrtoint ([0 x i8]* @global to i32) to i64) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR64_IDX64-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* -; PTR64_IDX64-NEXT: --> ((sext i32 ptrtoint ([0 x i8]* @global to i32) to i64) + %arg) U: full-set S: full-set Exits: ((sext i32 ptrtoint ([0 x i8]* @global to i32) to i64) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR64_IDX64-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 -; PTR64_IDX64-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } -; PTR64_IDX64-NEXT: %tmp18 = add i32 %tmp, 2 -; PTR64_IDX64-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR64_IDX64-NEXT: Determining loop execution counts for: @trunc_ptr_to_i32 -; PTR64_IDX64-NEXT: Loop %bb11: Unpredictable backedge-taken count. -; PTR64_IDX64-NEXT: Loop %bb11: Unpredictable max backedge-taken count. -; PTR64_IDX64-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. +; X64-LABEL: 'trunc_ptr_to_i32' +; X64-NEXT: Classifying expressions for: @trunc_ptr_to_i32 +; X64-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] +; X64-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } +; X64-NEXT: %tmp12 = getelementptr i8, i8* %arg, i32 ptrtoint ([0 x i8]* @global to i32) +; X64-NEXT: --> ((sext i32 ptrtoint ([0 x i8]* @global to i32) to i64) + %arg) U: full-set S: full-set Exits: ((sext i32 ptrtoint ([0 x i8]* @global to i32) to i64) + %arg) LoopDispositions: { %bb11: Invariant } +; X64-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* +; X64-NEXT: --> ((sext i32 ptrtoint ([0 x i8]* @global to i32) to i64) + %arg) U: full-set S: full-set Exits: ((sext i32 ptrtoint ([0 x i8]* @global to i32) to i64) + %arg) LoopDispositions: { %bb11: Invariant } +; X64-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 +; X64-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } +; X64-NEXT: %tmp18 = add i32 %tmp, 2 +; X64-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } +; X64-NEXT: Determining loop execution counts for: @trunc_ptr_to_i32 +; X64-NEXT: Loop %bb11: Unpredictable backedge-taken count. +; X64-NEXT: Loop %bb11: Unpredictable max backedge-taken count. +; X64-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. ; -; PTR64_IDX32-LABEL: 'trunc_ptr_to_i32' -; PTR64_IDX32-NEXT: Classifying expressions for: @trunc_ptr_to_i32 -; PTR64_IDX32-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] -; PTR64_IDX32-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR64_IDX32-NEXT: %tmp12 = getelementptr i8, i8* %arg, i32 ptrtoint ([0 x i8]* @global to i32) -; PTR64_IDX32-NEXT: --> (ptrtoint ([0 x i8]* @global to i32) + %arg) U: full-set S: full-set Exits: (ptrtoint ([0 x i8]* @global to i32) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR64_IDX32-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* -; PTR64_IDX32-NEXT: --> (ptrtoint ([0 x i8]* @global to i32) + %arg) U: full-set S: full-set Exits: (ptrtoint ([0 x i8]* @global to i32) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR64_IDX32-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 -; PTR64_IDX32-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } -; PTR64_IDX32-NEXT: %tmp18 = add i32 %tmp, 2 -; PTR64_IDX32-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR64_IDX32-NEXT: Determining loop execution counts for: @trunc_ptr_to_i32 -; PTR64_IDX32-NEXT: Loop %bb11: Unpredictable backedge-taken count. -; PTR64_IDX32-NEXT: Loop %bb11: Unpredictable max backedge-taken count. -; PTR64_IDX32-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. -; -; PTR16_IDX16-LABEL: 'trunc_ptr_to_i32' -; PTR16_IDX16-NEXT: Classifying expressions for: @trunc_ptr_to_i32 -; PTR16_IDX16-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] -; PTR16_IDX16-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR16_IDX16-NEXT: %tmp12 = getelementptr i8, i8* %arg, i32 ptrtoint ([0 x i8]* @global to i32) -; PTR16_IDX16-NEXT: --> ((trunc i32 ptrtoint ([0 x i8]* @global to i32) to i16) + %arg) U: full-set S: full-set Exits: ((trunc i32 ptrtoint ([0 x i8]* @global to i32) to i16) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR16_IDX16-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* -; PTR16_IDX16-NEXT: --> ((trunc i32 ptrtoint ([0 x i8]* @global to i32) to i16) + %arg) U: full-set S: full-set Exits: ((trunc i32 ptrtoint ([0 x i8]* @global to i32) to i16) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR16_IDX16-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 -; PTR16_IDX16-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } -; PTR16_IDX16-NEXT: %tmp18 = add i32 %tmp, 2 -; PTR16_IDX16-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR16_IDX16-NEXT: Determining loop execution counts for: @trunc_ptr_to_i32 -; PTR16_IDX16-NEXT: Loop %bb11: Unpredictable backedge-taken count. -; PTR16_IDX16-NEXT: Loop %bb11: Unpredictable max backedge-taken count. -; PTR16_IDX16-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. -; -; PTR16_IDX32-LABEL: 'trunc_ptr_to_i32' -; PTR16_IDX32-NEXT: Classifying expressions for: @trunc_ptr_to_i32 -; PTR16_IDX32-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] -; PTR16_IDX32-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR16_IDX32-NEXT: %tmp12 = getelementptr i8, i8* %arg, i32 ptrtoint ([0 x i8]* @global to i32) -; PTR16_IDX32-NEXT: --> (ptrtoint ([0 x i8]* @global to i32) + %arg) U: [0,131071) S: full-set Exits: (ptrtoint ([0 x i8]* @global to i32) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR16_IDX32-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* -; PTR16_IDX32-NEXT: --> (ptrtoint ([0 x i8]* @global to i32) + %arg) U: [0,131071) S: full-set Exits: (ptrtoint ([0 x i8]* @global to i32) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR16_IDX32-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 -; PTR16_IDX32-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } -; PTR16_IDX32-NEXT: %tmp18 = add i32 %tmp, 2 -; PTR16_IDX32-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR16_IDX32-NEXT: Determining loop execution counts for: @trunc_ptr_to_i32 -; PTR16_IDX32-NEXT: Loop %bb11: Unpredictable backedge-taken count. -; PTR16_IDX32-NEXT: Loop %bb11: Unpredictable max backedge-taken count. -; PTR16_IDX32-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. +; X32-LABEL: 'trunc_ptr_to_i32' +; X32-NEXT: Classifying expressions for: @trunc_ptr_to_i32 +; X32-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] +; X32-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } +; X32-NEXT: %tmp12 = getelementptr i8, i8* %arg, i32 ptrtoint ([0 x i8]* @global to i32) +; X32-NEXT: --> ((trunc i32 ptrtoint ([0 x i8]* @global to i32) to i16) + %arg) U: full-set S: full-set Exits: ((trunc i32 ptrtoint ([0 x i8]* @global to i32) to i16) + %arg) LoopDispositions: { %bb11: Invariant } +; X32-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* +; X32-NEXT: --> ((trunc i32 ptrtoint ([0 x i8]* @global to i32) to i16) + %arg) U: full-set S: full-set Exits: ((trunc i32 ptrtoint ([0 x i8]* @global to i32) to i16) + %arg) LoopDispositions: { %bb11: Invariant } +; X32-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 +; X32-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } +; X32-NEXT: %tmp18 = add i32 %tmp, 2 +; X32-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } +; X32-NEXT: Determining loop execution counts for: @trunc_ptr_to_i32 +; X32-NEXT: Loop %bb11: Unpredictable backedge-taken count. +; X32-NEXT: Loop %bb11: Unpredictable max backedge-taken count. +; X32-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. ; bb: br label %bb11 @@ -187,73 +119,39 @@ br label %bb11 } define hidden i32* @trunc_ptr_to_i128(i8* %arg, i32* %arg10) { -; PTR64_IDX64-LABEL: 'trunc_ptr_to_i128' -; PTR64_IDX64-NEXT: Classifying expressions for: @trunc_ptr_to_i128 -; PTR64_IDX64-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] -; PTR64_IDX64-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR64_IDX64-NEXT: %tmp12 = getelementptr i8, i8* %arg, i128 ptrtoint ([0 x i8]* @global to i128) -; PTR64_IDX64-NEXT: --> ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i64) + %arg) U: full-set S: full-set Exits: ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i64) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR64_IDX64-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* -; PTR64_IDX64-NEXT: --> ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i64) + %arg) U: full-set S: full-set Exits: ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i64) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR64_IDX64-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 -; PTR64_IDX64-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } -; PTR64_IDX64-NEXT: %tmp18 = add i32 %tmp, 2 -; PTR64_IDX64-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR64_IDX64-NEXT: Determining loop execution counts for: @trunc_ptr_to_i128 -; PTR64_IDX64-NEXT: Loop %bb11: Unpredictable backedge-taken count. -; PTR64_IDX64-NEXT: Loop %bb11: Unpredictable max backedge-taken count. -; PTR64_IDX64-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. +; X64-LABEL: 'trunc_ptr_to_i128' +; X64-NEXT: Classifying expressions for: @trunc_ptr_to_i128 +; X64-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] +; X64-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } +; X64-NEXT: %tmp12 = getelementptr i8, i8* %arg, i128 ptrtoint ([0 x i8]* @global to i128) +; X64-NEXT: --> ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i64) + %arg) U: full-set S: full-set Exits: ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i64) + %arg) LoopDispositions: { %bb11: Invariant } +; X64-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* +; X64-NEXT: --> ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i64) + %arg) U: full-set S: full-set Exits: ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i64) + %arg) LoopDispositions: { %bb11: Invariant } +; X64-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 +; X64-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } +; X64-NEXT: %tmp18 = add i32 %tmp, 2 +; X64-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } +; X64-NEXT: Determining loop execution counts for: @trunc_ptr_to_i128 +; X64-NEXT: Loop %bb11: Unpredictable backedge-taken count. +; X64-NEXT: Loop %bb11: Unpredictable max backedge-taken count. +; X64-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. ; -; PTR64_IDX32-LABEL: 'trunc_ptr_to_i128' -; PTR64_IDX32-NEXT: Classifying expressions for: @trunc_ptr_to_i128 -; PTR64_IDX32-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] -; PTR64_IDX32-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR64_IDX32-NEXT: %tmp12 = getelementptr i8, i8* %arg, i128 ptrtoint ([0 x i8]* @global to i128) -; PTR64_IDX32-NEXT: --> ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i32) + %arg) U: full-set S: full-set Exits: ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i32) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR64_IDX32-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* -; PTR64_IDX32-NEXT: --> ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i32) + %arg) U: full-set S: full-set Exits: ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i32) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR64_IDX32-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 -; PTR64_IDX32-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } -; PTR64_IDX32-NEXT: %tmp18 = add i32 %tmp, 2 -; PTR64_IDX32-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR64_IDX32-NEXT: Determining loop execution counts for: @trunc_ptr_to_i128 -; PTR64_IDX32-NEXT: Loop %bb11: Unpredictable backedge-taken count. -; PTR64_IDX32-NEXT: Loop %bb11: Unpredictable max backedge-taken count. -; PTR64_IDX32-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. -; -; PTR16_IDX16-LABEL: 'trunc_ptr_to_i128' -; PTR16_IDX16-NEXT: Classifying expressions for: @trunc_ptr_to_i128 -; PTR16_IDX16-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] -; PTR16_IDX16-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR16_IDX16-NEXT: %tmp12 = getelementptr i8, i8* %arg, i128 ptrtoint ([0 x i8]* @global to i128) -; PTR16_IDX16-NEXT: --> ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i16) + %arg) U: full-set S: full-set Exits: ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i16) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR16_IDX16-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* -; PTR16_IDX16-NEXT: --> ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i16) + %arg) U: full-set S: full-set Exits: ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i16) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR16_IDX16-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 -; PTR16_IDX16-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } -; PTR16_IDX16-NEXT: %tmp18 = add i32 %tmp, 2 -; PTR16_IDX16-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR16_IDX16-NEXT: Determining loop execution counts for: @trunc_ptr_to_i128 -; PTR16_IDX16-NEXT: Loop %bb11: Unpredictable backedge-taken count. -; PTR16_IDX16-NEXT: Loop %bb11: Unpredictable max backedge-taken count. -; PTR16_IDX16-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. -; -; PTR16_IDX32-LABEL: 'trunc_ptr_to_i128' -; PTR16_IDX32-NEXT: Classifying expressions for: @trunc_ptr_to_i128 -; PTR16_IDX32-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] -; PTR16_IDX32-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR16_IDX32-NEXT: %tmp12 = getelementptr i8, i8* %arg, i128 ptrtoint ([0 x i8]* @global to i128) -; PTR16_IDX32-NEXT: --> ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i32) + %arg) U: [0,131071) S: full-set Exits: ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i32) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR16_IDX32-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* -; PTR16_IDX32-NEXT: --> ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i32) + %arg) U: [0,131071) S: full-set Exits: ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i32) + %arg) LoopDispositions: { %bb11: Invariant } -; PTR16_IDX32-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 -; PTR16_IDX32-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } -; PTR16_IDX32-NEXT: %tmp18 = add i32 %tmp, 2 -; PTR16_IDX32-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } -; PTR16_IDX32-NEXT: Determining loop execution counts for: @trunc_ptr_to_i128 -; PTR16_IDX32-NEXT: Loop %bb11: Unpredictable backedge-taken count. -; PTR16_IDX32-NEXT: Loop %bb11: Unpredictable max backedge-taken count. -; PTR16_IDX32-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. +; X32-LABEL: 'trunc_ptr_to_i128' +; X32-NEXT: Classifying expressions for: @trunc_ptr_to_i128 +; X32-NEXT: %tmp = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ] +; X32-NEXT: --> {0,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } +; X32-NEXT: %tmp12 = getelementptr i8, i8* %arg, i128 ptrtoint ([0 x i8]* @global to i128) +; X32-NEXT: --> ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i16) + %arg) U: full-set S: full-set Exits: ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i16) + %arg) LoopDispositions: { %bb11: Invariant } +; X32-NEXT: %tmp13 = bitcast i8* %tmp12 to i32* +; X32-NEXT: --> ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i16) + %arg) U: full-set S: full-set Exits: ((trunc i128 ptrtoint ([0 x i8]* @global to i128) to i16) + %arg) LoopDispositions: { %bb11: Invariant } +; X32-NEXT: %tmp14 = load i32, i32* %tmp13, align 4 +; X32-NEXT: --> %tmp14 U: full-set S: full-set Exits: <> LoopDispositions: { %bb11: Variant } +; X32-NEXT: %tmp18 = add i32 %tmp, 2 +; X32-NEXT: --> {2,+,2}<%bb11> U: [0,-1) S: [-2147483648,2147483647) Exits: <> LoopDispositions: { %bb11: Computable } +; X32-NEXT: Determining loop execution counts for: @trunc_ptr_to_i128 +; X32-NEXT: Loop %bb11: Unpredictable backedge-taken count. +; X32-NEXT: Loop %bb11: Unpredictable max backedge-taken count. +; X32-NEXT: Loop %bb11: Unpredictable predicated backedge-taken count. ; bb: br label %bb11 diff --git a/llvm/test/Transforms/PhaseOrdering/scev-custom-dl.ll b/llvm/test/Transforms/PhaseOrdering/scev-custom-dl.ll --- a/llvm/test/Transforms/PhaseOrdering/scev-custom-dl.ll +++ b/llvm/test/Transforms/PhaseOrdering/scev-custom-dl.ll @@ -10,7 +10,7 @@ ; CHECK: test1 ; The loop body contains two increments by %div. ; Make sure that 2*%div is recognizable, and not expressed as a bit mask of %d. -; CHECK: --> {%p,+,(8 * (%d /u 4))} +; CHECK: --> {%p,+,(8 * ((zext i32 %d to i40) /u 4))}<%for.body> U: full-set S: full-set Exits: ((504 * ((zext i32 %d to i40) /u 4)) + %p) define void @test1(i32 %d, i32* %p) nounwind uwtable ssp { entry: %div = udiv i32 %d, 4 @@ -39,7 +39,7 @@ ; CHECK: test1a ; Same thing as test1, but it is even more tempting to fold 2 * (%d /u 2) -; CHECK: --> {%p,+,(8 * (%d /u 2))} +; CHECK: --> {%p,+,(8 * ((zext i32 %d to i40) /u 2))}<%for.body> U: full-set S: full-set Exits: ((504 * ((zext i32 %d to i40) /u 2)) + %p) define void @test1a(i32 %d, i32* %p) nounwind uwtable ssp { entry: %div = udiv i32 %d, 2