diff --git a/lib/CliftTransforms/FieldAccessReplacement.cpp b/lib/CliftTransforms/FieldAccessReplacement.cpp index 8cc72f418..b5257603c 100644 --- a/lib/CliftTransforms/FieldAccessReplacement.cpp +++ b/lib/CliftTransforms/FieldAccessReplacement.cpp @@ -302,9 +302,11 @@ bool Replacement::replace(ExpressionOpInterface PointerToReplace, // component, we still emit a `imm 0` to represent the access to `[0]`. if (Access.Index.Constant != 0 or not Access.Index.Variable) { auto Index = Access.Index.Constant; - auto IntegerType = clift::IntegerType::get(Builder.getContext(), - IntegerKind::Generic, - PointerSize); + auto IntegerType = Access.Index.Variable ? + Access.Index.Variable.getType() : + clift::IntegerType::get(Builder.getContext(), + IntegerKind::Generic, + PointerSize); FixedIndexValue = Builder.create(PointerToReplaceLoc, IntegerType, Index); @@ -369,22 +371,19 @@ bool Replacement::replace(ExpressionOpInterface PointerToReplace, or not LeftoverOffset.LinearCombination.empty()) { // Cast pointer to integer - auto IntegerType = clift::IntegerType::get(Builder.getContext(), - IntegerKind::Generic, - PointerSize); + auto IntPtrType = clift::IntegerType::get(Builder.getContext(), + IntegerKind::Generic, + PointerSize); CurrentValue = Builder.create(PointerToReplaceLoc, - IntegerType, + IntPtrType, CurrentValue); // Add base offset if (!LeftoverOffset.BaseOffset.isZero()) { - auto IntegerType = clift::IntegerType::get(Builder.getContext(), - IntegerKind::Generic, - PointerSize); auto LeftoverOffsetValue = LeftoverOffset.BaseOffset.getSExtValue(); auto AddOperandValue = Builder.create(PointerToReplaceLoc, - IntegerType, + IntPtrType, LeftoverOffsetValue); CurrentValue = Builder.create(PointerToReplaceLoc, CurrentValue, @@ -395,12 +394,12 @@ bool Replacement::replace(ExpressionOpInterface PointerToReplace, for (const auto &Term : LeftoverOffset.LinearCombination) { // Multiply stride by index auto IndexValue = Builder.create(PointerToReplaceLoc, - IntegerType, + IntPtrType, Term.Idx.Constant .getSExtValue()); auto StrideValue = Builder .create(PointerToReplaceLoc, - IntegerType, + IntPtrType, Term.Stride.getSExtValue()); auto StridedValue = Builder.create(PointerToReplaceLoc, IndexValue, @@ -411,7 +410,7 @@ bool Replacement::replace(ExpressionOpInterface PointerToReplace, } // Cast back to pointer - auto PointerType = PointerType::get(CurrentValue.getType(), PointerSize); + auto PointerType = PointerType::get(IntPtrType, PointerSize); CurrentValue = Builder.create(PointerToReplaceLoc, PointerType, CurrentValue);