On Mon, Jul 25, 2011 at 5:33 AM, Uros Bizjak <ubiz...@gmail.com> wrote: > On Mon, Jul 25, 2011 at 3:58 AM, H.J. Lu <hjl.to...@gmail.com> wrote: > >>> You are not fixing the core of the problem... this is why you need so >>> much hacks and kludges at various places (some w.r.t. -fPIC already >>> existed, see the patch). Above, you correctly identified the problem, >>> so let's avoid gen_lowpart on SImode operands by not calling it >>> anymore. >>> >>> Attached patch effectively rewrites LEA handling. The trick is, that >>> instead of using Pmode operations in addresses, we use either SImode >>> or DImode operations to calculate the address on 64bit targets. Up to >>> now, address calculations strictly used Pmode, so SImode on 32bit >>> targets and DImode on 64bit targets. Recent patches to >>> ix86_decompose_address and ix86_legitimate_address_p relaxed this >>> requirement. >>> >>> Attached patch changes LEA patterns and LEA splitters to accept >>> addresses, calculated with either SImode or DImode operations.This >>> means, that on x64 targets, we don't use gen_lowpart on SImode >>> operands anymore. Since symbol references on x32 are in SImode, this >>> solves the problem. The patch also avoids generating SImode subregs of >>> DImode addresses and DImode zero_extends of SImode addresses, since >>> LEA insn does this for us automatically. >>> >>> Please also note the change to ix86_print_operand_address. To avoid >>> addr32 prefixes, we can force registers in DImode on 64bit targets >>> without any problems. On x32, we can investigate, if this change >>> avoids unnecessary LEAs (for PR 49781, patched gcc genrates 6 vs. 8). >> >> The testcase won't compile since PIC doesn't work: > > Well, I did say that -fPIC did not work. > >>> Patch was bootstrapped and regression tested on x86_64-pc-linux-gnu >>> {,-m32} with no regressions. H.J., can you please test it on x32? >> >> On x32, it failed: >> >> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49832 >> >>> BTW: -fPIC is not yet implemented on trunk and still fails there with >>> an (unrelated) error, I didn't check x32 branch. >>> >> >> This could be: >> >> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49833 > > Attached patch implements -fpic handling for x32. In x32 mode, we now > use x86_64_general_operand and corresponding "e" constraints for adds > in SImode, since it looks that invalid addresses can only be generated > through adds. This avoids a whole bunch of new predicates and > constraints. > > 2011-07-25 Uros Bizjak <ubiz...@gmail.com> > > PR target/47381 > PR target/49832 > PR target/49833 > * config/i386/i386.md (add_operand): New mode attribute. > (*movdi_internal_rex64): Remove mode from pic_32bit_operand check. > (*movsi_internal): Ditto. Use "e" constraint in alternative 2. > (*lea_1): Use SWI48 mode iterator. > (*lea_1_zext): New insn pattern. > (add<mode>3): Use <add_operand> predicate for operand 2. > (*add<mode>_1): Use <add_operand> predicate for operand 2. Use "le" > constraint for alternative 2. > (addsi_1_zext): Use addsi_operand predicate for operand 2. Use "le" > constraint for alternative 2. > (add->lea splitter): Check operand modes in insn constraint. Extend > operands less than SImode wide to SImode. > (add->lea zext splitter): Do not extend operands to DImode. > (*lea_general_1): Handle only QImode and HImode operands. > (*lea_general_2): Ditto. > (*lea_general_3): Ditto. > (*lea_general_1_zext): Remove. > (*lea_general_2_zext): Ditto. > (*lea_general_3_zext): Ditto. > (*lea_general_4): Check operand modes in insn constraint. Extend > operands less than SImode wide to SImode. > (ashift->lea splitter): Ditto. > * config/i386/i386.c (ix86_print_operand_address): Print address > registers with 'q' modifier on 64bit targets. > * config/i386/predicates.md (pic_32bit_opreand): Define as special > predicate. Reject non-SI and non-DI modes. > (addsi_operand): New predicate. > > Uros. >
X32 glibc is miscompiled: CPP='/export/build/gnu/gcc-x32/release/usr/gcc-4.7.0-x32/bin/gcc -mx32 -E -x c-header' /export/build/gnu/glibc-x32/build-x86_64-linux/elf/ld-linux-x32.so.2 --library-path /export/build/gnu/glibc-x32/build-x86_64-linux:/export/build/gnu/glibc-x32/build-x86_64-linux/math:/export/build/gnu/glibc-x32/build-x86_64-linux/elf:/export/build/gnu/glibc-x32/build-x86_64-linux/dlfcn:/export/build/gnu/glibc-x32/build-x86_64-linux/nss:/export/build/gnu/glibc-x32/build-x86_64-linux/nis:/export/build/gnu/glibc-x32/build-x86_64-linux/rt:/export/build/gnu/glibc-x32/build-x86_64-linux/resolv:/export/build/gnu/glibc-x32/build-x86_64-linux/crypt:/export/build/gnu/glibc-x32/build-x86_64-linux/nptl /export/build/gnu/glibc-x32/build-x86_64-linux/sunrpc/rpcgen -Y ../scripts -h rpcsvc/yppasswd.x -o /export/build/gnu/glibc-x32/build-x86_64-linux/sunrpc/rpcsvc/yppasswd.T make[5]: *** [/export/build/gnu/glibc-x32/build-x86_64-linux/sunrpc/rpcsvc/yppasswd.stmp] Segmentation fault (core dumped) Some LEA patterns are wrong for x32. I will investigate. -- H.J.