From 96aa751760b4efc3424a82b573057008bc639c3b Mon Sep 17 00:00:00 2001 From: Lukas Zaoral Date: Thu, 27 May 2021 21:20:58 +0200 Subject: llvm12: Implement llvm.{s,u}{max,min} intrinsics The vector variants are not implemented at the moment. See: https://reviews.llvm.org/D84125 Co-authored-by: Lukas Zaoral Co-authored-by: Martin Nowack --- lib/Core/Executor.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'lib/Core') diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp index aaa56a55..a8ca86c2 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp @@ -1720,6 +1720,35 @@ void Executor::executeCall(ExecutionState &state, KInstruction *ki, Function *f, break; } +#if LLVM_VERSION_CODE >= LLVM_VERSION(12, 0) + case Intrinsic::smax: + case Intrinsic::smin: + case Intrinsic::umax: + case Intrinsic::umin: { + if (isa(i->getOperand(0)->getType()) || + isa(i->getOperand(1)->getType())) + return terminateStateOnExecError( + state, "llvm.{s,u}{max,min} with vectors is not supported"); + + ref op1 = eval(ki, 1, state).value; + ref op2 = eval(ki, 2, state).value; + + ref cond = nullptr; + if (f->getIntrinsicID() == Intrinsic::smax) + cond = SgtExpr::create(op1, op2); + else if (f->getIntrinsicID() == Intrinsic::smin) + cond = SltExpr::create(op1, op2); + else if (f->getIntrinsicID() == Intrinsic::umax) + cond = UgtExpr::create(op1, op2); + else // (f->getIntrinsicID() == Intrinsic::umin) + cond = UltExpr::create(op1, op2); + + ref result = SelectExpr::create(cond, op1, op2); + bindLocal(ki, state, result); + break; + } +#endif + #if LLVM_VERSION_CODE >= LLVM_VERSION(7, 0) case Intrinsic::fshr: case Intrinsic::fshl: { -- cgit 1.4.1