Skip to content

Commit 7764bfd

Browse files
author
Andres Madrid Ucha
committed
I64lowering: fix BigInt mixing with Number values
When compiling with the -O0 flag, the CheerpWriter would use BigInt for the indices of get element ptr instructions that were never lowered to 32-bit integers. Therefore it is good to implement the lowering of 64-bit indices of GEP in the I64lowering pass so node does not complain when executing the js file.
1 parent 9af5430 commit 7764bfd

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

llvm/lib/CheerpUtils/I64Lowering.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,40 @@ struct I64LoweringVisitor: public InstVisitor<I64LoweringVisitor, HighInt>
914914
{
915915
return visitDivRem(I, "__udivti3");
916916
}
917+
HighInt visitGetElementPtrInst(GetElementPtrInst& I)
918+
{
919+
bool hasI64Index = false;
920+
for (Value *Index : I.indices())
921+
{
922+
if (Index->getType()->isIntegerTy(64))
923+
{
924+
hasI64Index = true;
925+
break;
926+
}
927+
}
928+
if (!hasI64Index)
929+
return HighInt();
930+
IRBuilder<> Builder(&I);
931+
SmallVector<Value*, 8> NewIndices;
932+
for (Value *Index : I.indices())
933+
{
934+
if (Index->getType()->isIntegerTy(64))
935+
{
936+
HighInt H = visitValue(Index);
937+
NewIndices.push_back(H.low);
938+
}
939+
else
940+
NewIndices.push_back(Index);
941+
}
942+
Value* NewGEP = Builder.CreateGEP(I.getSourceElementType(), I.getPointerOperand(), NewIndices, I.getName());
943+
cast<GetElementPtrInst>(NewGEP)->setIsInBounds(I.isInBounds());
944+
945+
I.replaceAllUsesWith(NewGEP);
946+
ToDelete.push_back(&I);
947+
Changed = true;
917948

949+
return HighInt();
950+
}
918951
HighInt visitFreeze (Instruction &I)
919952
{
920953
if(!I.getType()->isIntegerTy(64))

0 commit comments

Comments
 (0)