aboutsummaryrefslogtreecommitdiff
path: root/src/backend/jit/llvm/llvmjit_expr.c
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2024-11-15 10:06:36 +0200
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2024-11-15 10:06:36 +0200
commitcfd7f36c83cdcf6322c7ea0d1d9ef62bc2b00375 (patch)
tree9297405b6fcef59498574026a3fefc600c79528e /src/backend/jit/llvm/llvmjit_expr.c
parente468ec0fddcd93e282da6685b75d5687c2a87f2a (diff)
downloadpostgresql-cfd7f36c83cdcf6322c7ea0d1d9ef62bc2b00375.tar.gz
postgresql-cfd7f36c83cdcf6322c7ea0d1d9ef62bc2b00375.zip
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
Diffstat (limited to 'src/backend/jit/llvm/llvmjit_expr.c')
-rw-r--r--src/backend/jit/llvm/llvmjit_expr.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/src/backend/jit/llvm/llvmjit_expr.c b/src/backend/jit/llvm/llvmjit_expr.c
index 0b3b5748ea2..9cec17544b8 100644
--- a/src/backend/jit/llvm/llvmjit_expr.c
+++ b/src/backend/jit/llvm/llvmjit_expr.c
@@ -720,11 +720,6 @@ llvm_compile_expr(ExprState *state)
v_boolnull = l_load(b, TypeStorageBool, v_resnullp, "");
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 */
LLVMBuildCondBr(b,
LLVMBuildICmp(b, LLVMIntEQ, v_boolnull,
@@ -816,11 +811,6 @@ llvm_compile_expr(ExprState *state)
v_boolnull = l_load(b, TypeStorageBool, v_resnullp, "");
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,
LLVMBuildICmp(b, LLVMIntEQ, v_boolnull,
l_sbool_const(1), ""),
@@ -875,21 +865,22 @@ llvm_compile_expr(ExprState *state)
case EEOP_BOOL_NOT_STEP:
{
LLVMValueRef v_boolvalue;
- LLVMValueRef v_boolnull;
LLVMValueRef v_negbool;
- v_boolnull = l_load(b, TypeStorageBool, v_resnullp, "");
+ /* compute !boolvalue */
v_boolvalue = l_load(b, TypeSizeT, v_resvaluep, "");
-
v_negbool = LLVMBuildZExt(b,
LLVMBuildICmp(b, LLVMIntEQ,
v_boolvalue,
l_sizet_const(0),
""),
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);
LLVMBuildBr(b, opblocks[opno + 1]);
@@ -1615,7 +1606,6 @@ llvm_compile_expr(ExprState *state)
LLVMPositionBuilderAtEnd(b, b_argsequal);
LLVMBuildStore(b, l_sbool_const(1), v_resnullp);
LLVMBuildStore(b, l_sizet_const(0), v_resvaluep);
- LLVMBuildStore(b, v_retval, v_resvaluep);
LLVMBuildBr(b, opblocks[opno + 1]);
break;