6

I was wondering if there's a way to disable predication in gcc/g++. When I get the object dump of my code, I don't want there to be any CMOV, CCMP, etc instructions in it.

I have gone through the gcc man page without any success. So far the only way ahead seems to be hacking into gcc itself. Using gcc 4.3 on RHEL x86_64 machine. Any ideas?

Thanks in advance.

antitalented
  • 111
  • 1
  • 5

3 Answers3

5

I ran into that problem before and in my case the solution was to disable if-conversion. You can use the compilation flags:

-fno-if-conversion -fno-if-conversion2 
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
user569115
  • 51
  • 3
  • The suggestion seems correct according to the documentation, but I still was unable to avoid `CMOV`s even with these flags. – alecov Jan 15 '17 at 15:02
  • 1
    @alecov - try throwing a `-fno-tree-loop-if-convert` on there as well, it worked for me in a case where the other two arguments didn't. – BeeOnRope Jul 15 '18 at 02:23
2

Try the following arguments on the gcc command line:

-fno-if-conversion -fno-if-conversion2 -fno-tree-loop-if-convert

This worked for me and the trick was the last argument, which is needed for some cases where ifs are converted to conditional moves inside loops, and these cases aren't covered by the other two arguments.

I discovered this based on this conversation from the gcc mailing lists:

--- Comment #1 from Andrew Pinski --- I don't think -fno-if-conversion and -fno-if-conversion2 are designed to turn off all predicated instructions.

Note -O3 turns on -ftree-loop-if-convert which also causes production of predicated instructions (predicated moves).

BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
2

You could try targetting a previous x86 instruction set that didn't have these instructions?

http://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Target-Options.html

gcc -b i386 main.c

(I've not tried this)

James
  • 9,064
  • 3
  • 31
  • 49
  • Thanks for the direction James. I read the article you posted. gcc says "unrecognized option '-b'". Not exactly sure why. Tried -march=i386. Got "error: CPU you selected does not support x86-64 instruction set". Same for -mtune=i386. I am still searching for a solution along your idea though. – antitalented Mar 08 '11 at 15:59