From patchwork Mon Jul 19 23:36:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schmidt X-Patchwork-Id: 59232 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id B1B16B6F06 for ; Tue, 20 Jul 2010 09:37:14 +1000 (EST) Received: (qmail 28550 invoked by alias); 19 Jul 2010 23:37:12 -0000 Received: (qmail 28538 invoked by uid 22791); 19 Jul 2010 23:37:11 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 19 Jul 2010 23:37:01 +0000 Received: (qmail 13263 invoked from network); 19 Jul 2010 23:36:59 -0000 Received: from unknown (HELO ?84.152.189.214?) (bernds@127.0.0.2) by mail.codesourcery.com with ESMTPA; 19 Jul 2010 23:36:59 -0000 Message-ID: <4C44E173.4050300@codesourcery.com> Date: Tue, 20 Jul 2010 01:36:19 +0200 From: Bernd Schmidt User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.10) Gecko/20100625 Thunderbird/3.0.5 MIME-Version: 1.0 To: GCC Patches CC: Richard Earnshaw Subject: Improve additions involving SP on Thumb-1 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Thumb-1 supports a range of up to 1020 for add insns of the form add rn, sp, #1020 If the constant is somewhat larger, we can do it with a sequence of two adds, which is better than the available alternatives: - ldr r4, .L64+12 - add r4, r4, sp + add r4, sp, #1020 + add r4, r4, #224 or - mov r0, #156 - lsl r0, r0, #3 - add r0, r0, sp + add r0, sp, #1020 + add r0, r0, #228 It's conceivable that we might even prefer a three-insn add sequence over either of these alternatives, but the following patch doesn't do this. Regression tested on arm-linux, with one extra timeout (which comes and goes - it went away vs. baseline for a different set of compiler flags). Ok? Bernd * config/arm/arm.md (thumb1_addsi3): Add alternative and split for computing the sum of the stack pointer and a large constant. * config/arm/constraints.md (M): Remove superfluous parentheses. (Pc): New constraint. Index: config/arm/arm.md =================================================================== --- config/arm/arm.md (revision 162287) +++ config/arm/arm.md (working copy) @@ -638,9 +638,9 @@ (define_insn_and_split "*arm_addsi3" ) (define_insn_and_split "*thumb1_addsi3" - [(set (match_operand:SI 0 "register_operand" "=l,l,l,*rk,*hk,l,k,l,l") - (plus:SI (match_operand:SI 1 "register_operand" "%0,0,l,*0,*0,k,k,0,l") - (match_operand:SI 2 "nonmemory_operand" "I,J,lL,*hk,*rk,M,O,Pa,Pb")))] + [(set (match_operand:SI 0 "register_operand" "=l,l,l,*rk,*hk,l,k,l,l,l") + (plus:SI (match_operand:SI 1 "register_operand" "%0,0,l,*0,*0,k,k,0,l,k") + (match_operand:SI 2 "nonmemory_operand" "I,J,lL,*hk,*rk,M,O,Pa,Pb,Pc")))] "TARGET_THUMB1" "* static const char * const asms[] = @@ -653,6 +653,7 @@ (define_insn_and_split "*thumb1_addsi3" \"add\\t%0, %1, %2\", \"add\\t%0, %1, %2\", \"#\", + \"#\", \"#\" }; if ((which_alternative == 2 || which_alternative == 6) @@ -662,21 +663,27 @@ (define_insn_and_split "*thumb1_addsi3" return asms[which_alternative]; " "&& reload_completed && CONST_INT_P (operands[2]) - && operands[1] != stack_pointer_rtx - && (INTVAL (operands[2]) > 255 || INTVAL (operands[2]) < -255)" + && ((operands[1] != stack_pointer_rtx + && (INTVAL (operands[2]) > 255 || INTVAL (operands[2]) < -255)) + || (operands[1] == stack_pointer_rtx + && INTVAL (operands[2]) > 1020))" [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2))) (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))] { HOST_WIDE_INT offset = INTVAL (operands[2]); - if (offset > 255) - offset = 255; - else if (offset < -255) - offset = -255; - + if (operands[1] == stack_pointer_rtx) + offset -= 1020; + else + { + if (offset > 255) + offset = 255; + else if (offset < -255) + offset = -255; + } operands[3] = GEN_INT (offset); operands[2] = GEN_INT (INTVAL (operands[2]) - offset); } - [(set_attr "length" "2,2,2,2,2,2,2,4,4")] + [(set_attr "length" "2,2,2,2,2,2,2,4,4,4")] ) ;; Reloading and elimination of the frame pointer can Index: config/arm/constraints.md =================================================================== --- config/arm/constraints.md (revision 162287) +++ config/arm/constraints.md (working copy) @@ -122,7 +122,7 @@ (define_constraint "M" (and (match_code "const_int") (match_test "TARGET_32BIT ? ((ival >= 0 && ival <= 32) || ((ival & (ival - 1)) == 0)) - : ((ival >= 0 && ival <= 1020) && ((ival & 3) == 0))"))) + : ival >= 0 && ival <= 1020 && (ival & 3) == 0"))) (define_constraint "N" "Thumb-1 state a constant in the range 0-31." @@ -148,6 +148,12 @@ (define_constraint "Pb" (match_test "TARGET_THUMB1 && ival >= -262 && ival <= 262 && (ival > 255 || ival < -255)"))) +(define_constraint "Pc" + "@internal In Thumb-1 state a constant that is in the range 1021 to 1275" + (and (match_code "const_int") + (match_test "TARGET_THUMB1 + && ival > 1020 && ival <= 1275"))) + (define_constraint "Ps" "@internal In Thumb-2 state a constant in the range -255 to +255" (and (match_code "const_int")