fix two transposed lines duncan caught and add an explanatory comment.
authorChris Lattner <sabre@nondot.org>
Thu, 26 Nov 2009 18:35:46 +0000 (18:35 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 26 Nov 2009 18:35:46 +0000 (18:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89958 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ValueTracking.cpp

index 37d5ad328701f962e5c9fe1494ac42e28f03d1e2..5439bbff269e6047aec4037d74866bb2d93e7cf8 100644 (file)
@@ -1064,12 +1064,15 @@ const Value *llvm::DecomposeGEPExpression(const Value *V, int64_t &BaseOffs,
       
       uint64_t Scale = TD->getTypeAllocSize(*GTI);
       
+      // Use GetLinearExpression to decompose the index into a C1*V+C2 form.
       unsigned Width = cast<IntegerType>(Index->getType())->getBitWidth();
       APInt IndexScale(Width, 0), IndexOffset(Width, 0);
       Index = GetLinearExpression(Index, IndexScale, IndexOffset, TD);
       
-      Scale *= IndexScale.getZExtValue();
+      // The GEP index scale ("Scale") scales C1*V+C2, yielding (C1*V+C2)*Scale.
+      // This gives us an aggregate computation of (C1*Scale)*V + C2*Scale.
       BaseOffs += IndexOffset.getZExtValue()*Scale;
+      Scale *= IndexScale.getZExtValue();
       
       
       // If we already had an occurrance of this index variable, merge this