Re: Do we work with LLVM 12 on s390x?

From: Andres Freund <andres(at)anarazel(dot)de>
To: Tom Stellard <tstellar(at)redhat(dot)com>
Cc: Honza Horak <hhorak(at)redhat(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Do we work with LLVM 12 on s390x?
Date: 2021-04-22 22:25:02
Message-ID: 20210422222502.xphkjpywzvfmva76@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2021-04-22 09:35:48 -0700, Tom Stellard wrote:
> On 4/21/21 6:40 AM, Honza Horak wrote:
> I wrote a new patch based on the bug discussion[1]. It works around
> the issue specifically on s390x rather than disabling specific
> CPUs and features for all targets. The patch is attached.

Cool, this is a pretty clear improvement. There's a few minor things I'd
change to fit it into PG - do you mind if I send that to the thread at
[1] for you to test before I push it?

> +/*
> + * For the systemz target, LLVM uses a different datalayout for z13 and newer
> + * CPUs than it does for older CPUs. This can cause a mismatch in datalayouts
> + * in the case where the llvm_types_module is compiled with a pre-z13 CPU
> + * and the JIT is running on z13 or newer.
> + * See computeDataLayout() function in
> + * llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp for information on the
> + * datalayout differences.
> + */
> +static bool
> +needs_systemz_workaround(void)
> +{
> + bool ret = false;
> + LLVMContextRef llvm_context;
> + LLVMTypeRef vec_type;
> + LLVMTargetDataRef llvm_layoutref;
> + if (strncmp(LLVMGetTargetName(llvm_targetref), "systemz", strlen("systemz")))
> + {
> + return false;
> + }
> +
> + llvm_context = LLVMGetModuleContext(llvm_types_module);
> + vec_type = LLVMVectorType(LLVMIntTypeInContext(llvm_context, 32), 4);
> + llvm_layoutref = LLVMCreateTargetData(llvm_layout);
> + ret = (LLVMABIAlignmentOfType(llvm_layoutref, vec_type) == 16);
> + LLVMDisposeTargetData(llvm_layoutref);
> + return ret;
> +}

I wonder if it'd be better to compare LLVMCopyStringRepOfTargetData() of
the llvm_types_module with the one of the JIT target machine, and only
specify -vector in that case? We currently support older LLVM versions
than the one that introduced the vector specific handling for systemz,
and I don't know what'd happen if we unnecessarily specified -vector.

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2021-04-22 22:35:41 Re: RFE: Make statistics robust for unplanned events
Previous Message Peter Geoghegan 2021-04-22 22:22:49 Re: RFE: Make statistics robust for unplanned events