From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24086 invoked by alias); 22 Dec 2014 22:27:48 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 24057 invoked by uid 48); 22 Dec 2014 22:27:43 -0000 From: "olegendo at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/53987] [SH] Unnecessary zero-extensions Date: Mon, 22 Dec 2014 22:27:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 4.8.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: olegendo at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-12/txt/msg02612.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53987 --- Comment #6 from Oleg Endo --- In the following example function bool stack_is_background_free( unsigned short* _data, const size_t _size){ size_t num_pixels_above_128 = 0; for(size_t index = 0;index< _size;++index){ if(_data[index] > 128) num_pixels_above_128++; } return num_pixels_above_128 == _size; } unsigned 16 bit values are compared against an 8 bit constant, which results in the following code: mov.w @r4+,r1 extu.w r1,r1 cmp/hi r7,r1 mov #0,r1 addc r1,r3 dt r2 bf .L4 In this case, the zero extension can be omitted, since the comparison result will always be 'true' if any bits >= 8 in the 16 bit value are set: 0x8000 (sign extend) -> 0xFFFF8000 (unsigned) > 0x80 = 1 0x8000 (zero extend) -> 0x00008000 (unsigned) > 0x80 = 1 The same would also apply for 8 bit values: int test (unsigned char* x) { return x[0] >= 127; } compiles to: mov.b @r4,r1 mov #126,r2 extu.b r1,r1 cmp/hi r2,r1 rts movt r0 0x80 (sign extend) -> 0xFFFFFF80 (unsigned) > 0x7E = 1 0x80 (zero extend) -> 0x00000080 (unsigned) > 0x7E = 1