Bug 53291 - Code generated for xtest is wrong
Summary: Code generated for xtest is wrong
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-09 07:32 UTC by Yukhin Kirill
Modified: 2012-08-22 21:07 UTC (History)
4 users (show)

See Also:
Host:
Target: x86
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-05-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yukhin Kirill 2012-05-09 07:32:06 UTC
Hi, 
Andi discovered that xtest instruction generation is wrong.
It generates

  xorl    %esi, %esi
  xtest
  sete    %sil

but correct is reverse

  movl $1,%esi
  xtest
  setne %sil
Comment 1 Andrew Pinski 2012-05-09 15:17:03 UTC
Testcase?
Comment 2 Yukhin Kirill 2012-05-09 16:53:12 UTC
(In reply to comment #1)
> Testcase?

It is trivial, so posting right here:

#include <immintrin.h>
unsigned a;
int
rtm_xtest (void)
{
  if (_xtest ())
    a = 1;
}

./build-x86_64-linux/gcc/xgcc -B./build-x86_64-linux/gcc 1.c -S -mrtm
$ cat 1.s
...
        xtest
        sete    %al
        movsbl  %al, %eax
        testl   %eax, %eax
        je      .L4
        movl    $1, a(%rip)
...
Comment 3 Andi Kleen 2012-05-09 17:17:56 UTC
Correction. We can keep the xor %reg,%reg. We just need it because setnz only sets 8 bit to initialize the higher order bits. 

Alternatively the value can be zero extended afterwards or just stay at 8 bit if there is no need for it.
Comment 4 Uroš Bizjak 2012-05-10 19:46:43 UTC
I am confused... is there anything wrong with current implementation or not?
Comment 5 Uroš Bizjak 2012-05-10 20:00:45 UTC
Try this patch:

Index: config/i386/i386.md
===================================================================
--- config/i386/i386.md (revision 187372)
+++ config/i386/i386.md (working copy)
@@ -18422,7 +18422,7 @@
 {
   emit_insn (gen_xtest_1 ());
 
-  ix86_expand_setcc (operands[0], EQ,
+  ix86_expand_setcc (operands[0], NE,
                     gen_rtx_REG (CCZmode, FLAGS_REG), const0_rtx);
   DONE;
 })
Comment 6 Andi Kleen 2012-05-10 22:52:30 UTC
Uros patch fixes it and the code is correct now. Please commit.


However in testing it I quickly hit PR53315
Comment 7 uros 2012-05-10 23:31:14 UTC
Author: uros
Date: Thu May 10 23:31:03 2012
New Revision: 187387

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187387
Log:
	PR target/53291
	* config/i386/i386.md (xtest): Use NE condition in ix86_expand_setcc.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.md
Comment 8 H.J. Lu 2012-05-11 02:41:55 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > Testcase?
> 
> It is trivial, so posting right here:
> 

We need a run-time testcase.
Comment 9 Andi Kleen 2012-05-11 03:36:11 UTC
The example in PR53315 is a runtime test case, except:
- it needs cpuid checks to be part of the test suite
- the printfs need to be replaced with asserts
- it needs to stop iceing first
Comment 10 Uroš Bizjak 2012-05-11 09:49:12 UTC
(In reply to comment #9)
> The example in PR53315 is a runtime test case, except:
> - it needs cpuid checks to be part of the test suite
> - the printfs need to be replaced with asserts
> - it needs to stop iceing first

So, let's close this PR as FIXED.
Comment 11 eraman 2012-08-22 21:07:39 UTC
Author: eraman
Date: Wed Aug 22 21:07:30 2012
New Revision: 190601

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=190601
Log:
2012-08-22   Easwaran Raman  <eraman@google.com>
	Backport r187387 and r187477 from trunk.

	r187387:
	2012-05-11  Uros Bizjak  <ubizjak@gmail.com>
		PR target/53291
		* config/i386/i386.md (xtest): Use NE condition in ix86_expand_setcc.

	r187477:
	2012-05-14  Andrew Pinski  <apinski@cavium.com>
	    H.J. Lu  <hongjiu.lu@intel.com>
	    Jakub Jelinek  <jakub@redhat.com>
		PR target/53315
		* config/i386/i386.md (xbegin_1): Use + in constraint and
		match_dup.
		(xbegin): Updated.

gcc/testsuite/ChangeLog.google-4_7:
2012-08-22   Easwaran Raman  <eraman@google.com>
	Backport r187477 from trunk:

	2012-05-14  Andi Kleen <ak@linux.intel.com>
		    Jakub Jelinek  <jakub@redhat.com>
	
		PR target/53315
		* gcc.target/i386/i386.exp (check_effective_target_rtm): New.
		* gcc.target/i386/rtm-check.h: New file.
		* gcc.target/i386/pr53315.c: New test.


Added:
    branches/google/gcc-4_7/gcc/testsuite/gcc.target/i386/pr53315.c
      - copied unchanged from r187477, trunk/gcc/testsuite/gcc.target/i386/pr53315.c
    branches/google/gcc-4_7/gcc/testsuite/gcc.target/i386/rtm-check.h
      - copied unchanged from r187477, trunk/gcc/testsuite/gcc.target/i386/rtm-check.h
Modified:
    branches/google/gcc-4_7/gcc/ChangeLog.google-4_7
    branches/google/gcc-4_7/gcc/config/i386/i386.md
    branches/google/gcc-4_7/gcc/testsuite/ChangeLog.google-4_7
    branches/google/gcc-4_7/gcc/testsuite/gcc.target/i386/i386.exp