Skip to content

Commit

Permalink
Implemented abs intrinsic (JuliaHubOSS#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
niansa authored May 2, 2024
1 parent 2cca488 commit 3644957
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Target/CBackend/CBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2606,6 +2606,7 @@ void CWriter::generateHeader(Module &M) {
case Intrinsic::umin:
case Intrinsic::smin:
case Intrinsic::smax:
case Intrinsic::abs:
case Intrinsic::is_constant:
intrinsicsToDefine.push_back(&*I);
continue;
Expand Down Expand Up @@ -4698,6 +4699,9 @@ void CWriter::printIntrinsicDefinition(FunctionType *funT, unsigned Opcode,
case Intrinsic::smin:
Out << " r = a < b ? a : b;\n";
break;
case Intrinsic::abs:
Out << " r = a < 0 ? -a : a;\n";
break;
case Intrinsic::is_constant:
Out << " r = 0 /* llvm.is.constant */;\n";
break;
Expand Down Expand Up @@ -4824,6 +4828,7 @@ bool CWriter::lowerIntrinsics(Function &F) {
case Intrinsic::umin:
case Intrinsic::smin:
case Intrinsic::smax:
case Intrinsic::abs:
case Intrinsic::is_constant:
// We directly implement these intrinsics
break;
Expand Down Expand Up @@ -5145,6 +5150,7 @@ bool CWriter::visitBuiltinCall(CallInst &I, Intrinsic::ID ID) {
case Intrinsic::umin:
case Intrinsic::smax:
case Intrinsic::smin:
case Intrinsic::abs:
case Intrinsic::is_constant:
return false; // these use the normal function call emission
}
Expand Down

0 comments on commit 3644957

Please sign in to comment.