Skip to content

Commit cfd7f36

Browse files
committed
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
1 parent e468ec0 commit cfd7f36

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/backend/jit/llvm/llvmjit_expr.c

+7-17
Original file line numberDiff line numberDiff line change
@@ -720,11 +720,6 @@ llvm_compile_expr(ExprState *state)
720720
v_boolnull = l_load(b, TypeStorageBool, v_resnullp, "");
721721
v_boolvalue = l_load(b, TypeSizeT, v_resvaluep, "");
722722

723-
/* set resnull to boolnull */
724-
LLVMBuildStore(b, v_boolnull, v_resnullp);
725-
/* set revalue to boolvalue */
726-
LLVMBuildStore(b, v_boolvalue, v_resvaluep);
727-
728723
/* check if current input is NULL */
729724
LLVMBuildCondBr(b,
730725
LLVMBuildICmp(b, LLVMIntEQ, v_boolnull,
@@ -816,11 +811,6 @@ llvm_compile_expr(ExprState *state)
816811
v_boolnull = l_load(b, TypeStorageBool, v_resnullp, "");
817812
v_boolvalue = l_load(b, TypeSizeT, v_resvaluep, "");
818813

819-
/* set resnull to boolnull */
820-
LLVMBuildStore(b, v_boolnull, v_resnullp);
821-
/* set revalue to boolvalue */
822-
LLVMBuildStore(b, v_boolvalue, v_resvaluep);
823-
824814
LLVMBuildCondBr(b,
825815
LLVMBuildICmp(b, LLVMIntEQ, v_boolnull,
826816
l_sbool_const(1), ""),
@@ -875,21 +865,22 @@ llvm_compile_expr(ExprState *state)
875865
case EEOP_BOOL_NOT_STEP:
876866
{
877867
LLVMValueRef v_boolvalue;
878-
LLVMValueRef v_boolnull;
879868
LLVMValueRef v_negbool;
880869

881-
v_boolnull = l_load(b, TypeStorageBool, v_resnullp, "");
870+
/* compute !boolvalue */
882871
v_boolvalue = l_load(b, TypeSizeT, v_resvaluep, "");
883-
884872
v_negbool = LLVMBuildZExt(b,
885873
LLVMBuildICmp(b, LLVMIntEQ,
886874
v_boolvalue,
887875
l_sizet_const(0),
888876
""),
889877
TypeSizeT, "");
890-
/* set resnull to boolnull */
891-
LLVMBuildStore(b, v_boolnull, v_resnullp);
892-
/* set revalue to !boolvalue */
878+
879+
/*
880+
* Store it back in resvalue. We can ignore resnull here;
881+
* if it was true, it stays true, and the value we store
882+
* in resvalue doesn't matter.
883+
*/
893884
LLVMBuildStore(b, v_negbool, v_resvaluep);
894885

895886
LLVMBuildBr(b, opblocks[opno + 1]);
@@ -1615,7 +1606,6 @@ llvm_compile_expr(ExprState *state)
16151606
LLVMPositionBuilderAtEnd(b, b_argsequal);
16161607
LLVMBuildStore(b, l_sbool_const(1), v_resnullp);
16171608
LLVMBuildStore(b, l_sizet_const(0), v_resvaluep);
1618-
LLVMBuildStore(b, v_retval, v_resvaluep);
16191609

16201610
LLVMBuildBr(b, opblocks[opno + 1]);
16211611
break;

0 commit comments

Comments
 (0)