Skip to content

Commit 6b2a69c

Browse files
committed
LLVM: Use zero extension for unsigned int cast
1 parent 800be6b commit 6b2a69c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/libasr/codegen/asr_to_llvm.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6025,8 +6025,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
60256025
}
60266026
break;
60276027
}
6028-
case (ASR::cast_kindType::IntegerToInteger) :
6029-
case (ASR::cast_kindType::UnsignedIntegerToUnsignedInteger) : {
6028+
case (ASR::cast_kindType::IntegerToInteger) : {
60306029
int arg_kind = -1, dest_kind = -1;
60316030
extract_kinds(x, arg_kind, dest_kind);
60326031
if( arg_kind > 0 && dest_kind > 0 &&
@@ -6040,6 +6039,20 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
60406039
}
60416040
break;
60426041
}
6042+
case (ASR::cast_kindType::UnsignedIntegerToUnsignedInteger) : {
6043+
int arg_kind = -1, dest_kind = -1;
6044+
extract_kinds(x, arg_kind, dest_kind);
6045+
if( arg_kind > 0 && dest_kind > 0 &&
6046+
arg_kind != dest_kind )
6047+
{
6048+
if (dest_kind > arg_kind) {
6049+
tmp = builder->CreateZExt(tmp, llvm_utils->getIntType(dest_kind));
6050+
} else {
6051+
tmp = builder->CreateTrunc(tmp, llvm_utils->getIntType(dest_kind));
6052+
}
6053+
}
6054+
break;
6055+
}
60436056
case (ASR::cast_kindType::IntegerToUnsignedInteger) : {
60446057
int arg_kind = -1, dest_kind = -1;
60456058
extract_kinds(x, arg_kind, dest_kind);

0 commit comments

Comments
 (0)