This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Enable EBX for x86 in 32bits PIC code
- From: Ilya Enkovich <enkovich dot gnu at gmail dot com>
- To: Uros Bizjak <ubizjak at gmail dot com>
- Cc: Jeff Law <law at redhat dot com>, Vladimir Makarov <vmakarov at redhat dot com>, gcc at gnu dot org, gcc-patches <gcc-patches at gcc dot gnu dot org>, Evgeny Stupachenko <evstupac at gmail dot com>, Richard Biener <richard dot guenther at gmail dot com>
- Date: Thu, 28 Aug 2014 17:29:17 +0400
- Subject: Re: Enable EBX for x86 in 32bits PIC code
- Authentication-results: sourceware.org; auth=none
- References: <CAOvf_xxsQ_oYGqNAVQ1+BW+CuD3mzebZ2xma0jpF=WfyZMCRCA at mail dot gmail dot com> <CAFiYyc1mFtTezkTJORmJJq+yht=qPSwiN7KDn19+bSuSdaqvMQ at mail dot gmail dot com> <CAOvf_xyeVeg2oB9Xxz8RMEQ6gyfJY5whd9s4ygoAAEaMU9efnA at mail dot gmail dot com> <20140707114750 dot GB31640 at tucnak dot redhat dot com> <CAMbmDYZV_fx0jxmKHhLsC2pJ7pDzuu6toEAH72izOdpq6KGyfg at mail dot gmail dot com> <20140822121151 dot GA60032 at msticlxl57 dot ims dot intel dot com> <53FB5184 dot 3030500 at redhat dot com> <CAMbmDYbP77pmkqpJD8cnXbe7_8aRMnYF-tnfKRubULn8-aDCdw at mail dot gmail dot com> <CAMbmDYacBWjKtCYPB0A2m=fkUTk_Wt5D6f2aEkH7C3paWaR7ag at mail dot gmail dot com> <53FCA6F5 dot 7020405 at redhat dot com> <20140826213712 dot GA39451 at msticlxl57 dot ims dot intel dot com> <53FE5002 dot 6040005 at redhat dot com> <CAMbmDYbTA+=tqZO0g2OR8oWqEaUfzm8eAh+anNszKqO1z62P2Q at mail dot gmail dot com> <CAFULd4bMH6Rt=DvA7j6ZLgbt3BL8xL_xnLTWRGgjS9CYSW-8WQ at mail dot gmail dot com> <CAMbmDYb09zeYE6vpGzHjCUHf+c7SBcyhZo2=tT1gZ0v556boHQ at mail dot gmail dot com> <CAFULd4YaEDYcwJT1Dj6eqvfGkhTwQzd95o2uMiwi=VYonfVj1Q at mail dot gmail dot com>
2014-08-28 17:08 GMT+04:00 Uros Bizjak <ubizjak@gmail.com>:
> On Thu, Aug 28, 2014 at 2:54 PM, Ilya Enkovich <enkovich.gnu@gmail.com> wrote:
>
>>>>>> diff --git a/gcc/calls.c b/gcc/calls.c
>>>>>> index 4285ec1..85dae6b 100644
>>>>>> --- a/gcc/calls.c
>>>>>> +++ b/gcc/calls.c
>>>>>> @@ -1122,6 +1122,14 @@ initialize_argument_information (int num_actuals
>>>>>> ATTRIBUTE_UNUSED,
>>>>>> call_expr_arg_iterator iter;
>>>>>> tree arg;
>>>>>>
>>>>>> + if (targetm.calls.implicit_pic_arg (fndecl ? fndecl : fntype))
>>>>>> + {
>>>>>> + gcc_assert (pic_offset_table_rtx);
>>>>>> + args[j].tree_value = make_tree (ptr_type_node,
>>>>>> + pic_offset_table_rtx);
>>>>>> + j--;
>>>>>> + }
>>>>>> +
>>>>>> if (struct_value_addr_value)
>>>>>> {
>>>>>> args[j].tree_value = struct_value_addr_value;
>>>>>
>>>>> So why do you need this? Can't this be handled in the call/call_value
>>>>> expanders or what about attaching the use to CALL_INSN_FUNCTION_USAGE from
>>>>> inside ix86_expand_call? Basically I'm not seeing the need for another
>>>>> target hook here. I think that would significantly simply the patch as
>>>>> well.
>>>>
>>>> GOT base address become an additional implicit arg with EBX relaxed
>>>> and I handled it as all other args. I can move EBX initialization into
>>>> ix86_expand_call. Would still need some hint from target to init
>>>> pic_offset_table_rtx with proper value in the beginning of function
>>>> expand.
>>>
>>> Maybe you can you use get_hard_reg_initial_val for this?
>>
>> Actually there is no input hard reg holding GOT address. Currently I
>> use initialization with ebx with following ebx initialization in
>> prolog_epilog pass. But this is a temporary workaround. It is
>> inefficient because always uses callee save reg to get GOT address. I
>> suppose we should generate pseudo reg for pic_offset_table_rtx and
>> also set_got with this register as a destination in expand pass.
>> After register allocation set_got may be transformed into get_pc_thunk
>> call with proper hard reg. But some target hook has to be used for
>> this.
>
> Let me expand my idea a bit. IIRC, get_hard_reg_initial_val and
> friends will automatically emit intialization of a pseudo from
> pic_offset_table_rtx hard reg. After reload, real initialization of
> pic_offset_table_rtx hard reg is emitted in pro_and_epilogue pass. I
> don't know if this works with current implementation of dynamic
> pic_offset_table_rtx selection, though.
That means you should choose some hard reg early before register
allocation to be used for PIC reg initialization. I do not like we
have to do this and want to just generate set_got with pseudo reg and
do not involve any additional hard reg. That would look like
(insn/f 168 167 169 2 (parallel [
(set (reg:SI 127)
(unspec:SI [
(const_int 0 [0])
] UNSPEC_SET_GOT))
(clobber (reg:CC 17 flags))
]) test.cc:42 -1
(expr_list:REG_CFA_FLUSH_QUEUE (nil)
(nil)))
after expand pass. r127 is pic_offset_table_rtx here. And after
reload it would become:
(insn/f 168 167 169 2 (parallel [
(set (reg:SI 3 bx)
(unspec:SI [
(const_int 0 [0])
] UNSPEC_SET_GOT))
(clobber (reg:CC 17 flags))
]) test.cc:42 -1
(expr_list:REG_CFA_FLUSH_QUEUE (nil)
(nil)))
And no additional actions are required on pro_and_epilogue. Also it
simplifies analysis whether we should generate set_got at all.
Current we check hard reg is ever live which is wrong with not fixed
ebx because any usage of hard reg used to init GOT doesn't mean GOT
usage. And with my proposed scheme unused GOT would mean DCE just
removes useless set_got.
Ilya
>
> Uros.