Emit 'fneg' for unary minus with floating point operand.
Simple negation from 0 doesn't work in case -0.0 argument.
This commit is contained in:
committed by
Pavel Punegov
parent
b1f1cde535
commit
801f6a5036
+1
@@ -588,6 +588,7 @@ internal class FunctionGenerationContext(val function: LLVMValueRef,
|
|||||||
|
|
||||||
fun fsub(arg0: LLVMValueRef, arg1: LLVMValueRef, name: String = ""): LLVMValueRef = LLVMBuildFSub(builder, arg0, arg1, name)!!
|
fun fsub(arg0: LLVMValueRef, arg1: LLVMValueRef, name: String = ""): LLVMValueRef = LLVMBuildFSub(builder, arg0, arg1, name)!!
|
||||||
fun fadd(arg0: LLVMValueRef, arg1: LLVMValueRef, name: String = ""): LLVMValueRef = LLVMBuildFAdd(builder, arg0, arg1, name)!!
|
fun fadd(arg0: LLVMValueRef, arg1: LLVMValueRef, name: String = ""): LLVMValueRef = LLVMBuildFAdd(builder, arg0, arg1, name)!!
|
||||||
|
fun fneg(arg: LLVMValueRef, name: String = ""): LLVMValueRef = LLVMBuildFNeg(builder, arg, name)!!
|
||||||
|
|
||||||
fun select(ifValue: LLVMValueRef, thenValue: LLVMValueRef, elseValue: LLVMValueRef, name: String = ""): LLVMValueRef =
|
fun select(ifValue: LLVMValueRef, thenValue: LLVMValueRef, elseValue: LLVMValueRef, name: String = ""): LLVMValueRef =
|
||||||
LLVMBuildSelect(builder, ifValue, thenValue, elseValue, name)!!
|
LLVMBuildSelect(builder, ifValue, thenValue, elseValue, name)!!
|
||||||
|
|||||||
+2
-2
@@ -699,10 +699,10 @@ internal class IntrinsicGenerator(private val environment: IntrinsicGeneratorEnv
|
|||||||
private fun FunctionGenerationContext.emitUnaryMinus(args: List<LLVMValueRef>): LLVMValueRef {
|
private fun FunctionGenerationContext.emitUnaryMinus(args: List<LLVMValueRef>): LLVMValueRef {
|
||||||
val first = args[0]
|
val first = args[0]
|
||||||
val destTy = first.type
|
val destTy = first.type
|
||||||
val const0 = makeConstOfType(destTy, 0)
|
|
||||||
return if (destTy.isFloatingPoint()) {
|
return if (destTy.isFloatingPoint()) {
|
||||||
fsub(const0, first)
|
fneg(first)
|
||||||
} else {
|
} else {
|
||||||
|
val const0 = makeConstOfType(destTy, 0)
|
||||||
sub(const0, first)
|
sub(const0, first)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user