mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
jit: Stop emitting some unnecessary instructions
In EEOP_BOOL_AND_STEP* and EEOP_BOOL_OR_STEP*, we emitted pointlesss store instructions to store to resnull/resvalue values that were just loaded from the same fields in the previous instructions. They will surely get optimized away by LLVM if any optimizations are enabled, but it's better to not emit them in the first place. In EEOP_BOOL_NOT_STEP, similar story with resnull. In EEOP_NULLIF, when it returns NULL, there was also a redundant store to resvalue just after storing a 0 to it. The value of resvalue doesn't matter when resnull is set, so in fact even storing the 0 is unnecessary, but I kept that because we tend to do that for general tidiness. Author: Xing Guo <higuoxing@gmail.com> Reviewed-by: Andreas Karlsson <andreas@proxel.se> Discussion: https://www.postgresql.org/message-id/CACpMh%2BC%3Dg13WdvzLRSponsVWGgxwDSMzQWM4Gz0heOyaA0-N6g@mail.gmail.com
This commit is contained in:
@ -720,11 +720,6 @@ llvm_compile_expr(ExprState *state)
|
|||||||
v_boolnull = l_load(b, TypeStorageBool, v_resnullp, "");
|
v_boolnull = l_load(b, TypeStorageBool, v_resnullp, "");
|
||||||
v_boolvalue = l_load(b, TypeSizeT, v_resvaluep, "");
|
v_boolvalue = l_load(b, TypeSizeT, v_resvaluep, "");
|
||||||
|
|
||||||
/* set resnull to boolnull */
|
|
||||||
LLVMBuildStore(b, v_boolnull, v_resnullp);
|
|
||||||
/* set revalue to boolvalue */
|
|
||||||
LLVMBuildStore(b, v_boolvalue, v_resvaluep);
|
|
||||||
|
|
||||||
/* check if current input is NULL */
|
/* check if current input is NULL */
|
||||||
LLVMBuildCondBr(b,
|
LLVMBuildCondBr(b,
|
||||||
LLVMBuildICmp(b, LLVMIntEQ, v_boolnull,
|
LLVMBuildICmp(b, LLVMIntEQ, v_boolnull,
|
||||||
@ -816,11 +811,6 @@ llvm_compile_expr(ExprState *state)
|
|||||||
v_boolnull = l_load(b, TypeStorageBool, v_resnullp, "");
|
v_boolnull = l_load(b, TypeStorageBool, v_resnullp, "");
|
||||||
v_boolvalue = l_load(b, TypeSizeT, v_resvaluep, "");
|
v_boolvalue = l_load(b, TypeSizeT, v_resvaluep, "");
|
||||||
|
|
||||||
/* set resnull to boolnull */
|
|
||||||
LLVMBuildStore(b, v_boolnull, v_resnullp);
|
|
||||||
/* set revalue to boolvalue */
|
|
||||||
LLVMBuildStore(b, v_boolvalue, v_resvaluep);
|
|
||||||
|
|
||||||
LLVMBuildCondBr(b,
|
LLVMBuildCondBr(b,
|
||||||
LLVMBuildICmp(b, LLVMIntEQ, v_boolnull,
|
LLVMBuildICmp(b, LLVMIntEQ, v_boolnull,
|
||||||
l_sbool_const(1), ""),
|
l_sbool_const(1), ""),
|
||||||
@ -875,21 +865,22 @@ llvm_compile_expr(ExprState *state)
|
|||||||
case EEOP_BOOL_NOT_STEP:
|
case EEOP_BOOL_NOT_STEP:
|
||||||
{
|
{
|
||||||
LLVMValueRef v_boolvalue;
|
LLVMValueRef v_boolvalue;
|
||||||
LLVMValueRef v_boolnull;
|
|
||||||
LLVMValueRef v_negbool;
|
LLVMValueRef v_negbool;
|
||||||
|
|
||||||
v_boolnull = l_load(b, TypeStorageBool, v_resnullp, "");
|
/* compute !boolvalue */
|
||||||
v_boolvalue = l_load(b, TypeSizeT, v_resvaluep, "");
|
v_boolvalue = l_load(b, TypeSizeT, v_resvaluep, "");
|
||||||
|
|
||||||
v_negbool = LLVMBuildZExt(b,
|
v_negbool = LLVMBuildZExt(b,
|
||||||
LLVMBuildICmp(b, LLVMIntEQ,
|
LLVMBuildICmp(b, LLVMIntEQ,
|
||||||
v_boolvalue,
|
v_boolvalue,
|
||||||
l_sizet_const(0),
|
l_sizet_const(0),
|
||||||
""),
|
""),
|
||||||
TypeSizeT, "");
|
TypeSizeT, "");
|
||||||
/* set resnull to boolnull */
|
|
||||||
LLVMBuildStore(b, v_boolnull, v_resnullp);
|
/*
|
||||||
/* set revalue to !boolvalue */
|
* Store it back in resvalue. We can ignore resnull here;
|
||||||
|
* if it was true, it stays true, and the value we store
|
||||||
|
* in resvalue doesn't matter.
|
||||||
|
*/
|
||||||
LLVMBuildStore(b, v_negbool, v_resvaluep);
|
LLVMBuildStore(b, v_negbool, v_resvaluep);
|
||||||
|
|
||||||
LLVMBuildBr(b, opblocks[opno + 1]);
|
LLVMBuildBr(b, opblocks[opno + 1]);
|
||||||
@ -1615,7 +1606,6 @@ llvm_compile_expr(ExprState *state)
|
|||||||
LLVMPositionBuilderAtEnd(b, b_argsequal);
|
LLVMPositionBuilderAtEnd(b, b_argsequal);
|
||||||
LLVMBuildStore(b, l_sbool_const(1), v_resnullp);
|
LLVMBuildStore(b, l_sbool_const(1), v_resnullp);
|
||||||
LLVMBuildStore(b, l_sizet_const(0), v_resvaluep);
|
LLVMBuildStore(b, l_sizet_const(0), v_resvaluep);
|
||||||
LLVMBuildStore(b, v_retval, v_resvaluep);
|
|
||||||
|
|
||||||
LLVMBuildBr(b, opblocks[opno + 1]);
|
LLVMBuildBr(b, opblocks[opno + 1]);
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user