summaryrefslogtreecommitdiff
path: root/src/backend/jit/llvm
diff options
context:
space:
mode:
authorDavid Rowley2024-12-20 20:43:26 +0000
committerDavid Rowley2024-12-20 20:43:26 +0000
commitdb448ce5ad36a2754e4e75900b180260143aacf8 (patch)
tree54753cad82035c6a3cdf7edaa897291b09622d6b /src/backend/jit/llvm
parent1f81b48a9d567ae9074ab1f3233eae9997b3d7bd (diff)
Optimize alignment calculations in tuple form/deform
Here we convert CompactAttribute.attalign from a char, which is directly derived from pg_attribute.attalign into a uint8, which stores the number of bytes to align the column's value by in the tuple. This allows tuple deformation and tuple size calculations to move away from using the inefficient att_align_nominal() macro, which manually checks each TYPALIGN_* char to translate that into the alignment bytes for the given type. Effectively, this commit changes those to TYPEALIGN calls, which are branchless and only perform some simple arithmetic with some bit-twiddling. The removed branches were often mispredicted by CPUs, especially so in real-world tables which often contain a mishmash of different types with different alignment requirements. Author: David Rowley Reviewed-by: Andres Freund, Victor Yegorov Discussion: https://postgr.es/m/CAApHDvrBztXP3yx=NKNmo3xwFAFhEdyPnvrDg3=M0RhDs+4vYw@mail.gmail.com
Diffstat (limited to 'src/backend/jit/llvm')
-rw-r--r--src/backend/jit/llvm/llvmjit_deform.c17
1 files changed, 1 insertions, 16 deletions
diff --git a/src/backend/jit/llvm/llvmjit_deform.c b/src/backend/jit/llvm/llvmjit_deform.c
index f49e7bce7d0..88ef2bb06ce 100644
--- a/src/backend/jit/llvm/llvmjit_deform.c
+++ b/src/backend/jit/llvm/llvmjit_deform.c
@@ -395,7 +395,7 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc,
{
CompactAttribute *att = TupleDescCompactAttr(desc, attnum);
LLVMValueRef v_incby;
- int alignto;
+ int alignto = att->attalignby;
LLVMValueRef l_attno = l_int16_const(lc, attnum);
LLVMValueRef v_attdatap;
LLVMValueRef v_resultp;
@@ -494,21 +494,6 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc,
}
LLVMPositionBuilderAtEnd(b, attcheckalignblocks[attnum]);
- /* determine required alignment */
- if (att->attalign == TYPALIGN_INT)
- alignto = ALIGNOF_INT;
- else if (att->attalign == TYPALIGN_CHAR)
- alignto = 1;
- else if (att->attalign == TYPALIGN_DOUBLE)
- alignto = ALIGNOF_DOUBLE;
- else if (att->attalign == TYPALIGN_SHORT)
- alignto = ALIGNOF_SHORT;
- else
- {
- elog(ERROR, "unknown alignment");
- alignto = 0;
- }
-
/* ------
* Even if alignment is required, we can skip doing it if provably
* unnecessary: