https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63783

--- Comment #4 from Oleg Endo <olegendo at gcc dot gnu.org> ---
(In reply to Michael Karcher from comment #3)
> Created attachment 33954 [details]
> Remove assumption that "not" is logical negate
> 
> Indeed the treg combine pass is broken. Thanks to the nicely documented
> code, it could easily be determined, that this optimization pass contains
> the wrong assumption that "not" is an assembler instruction that can be used
> for logical negation of a register. As this is a bitwise negate instruction,
> it can not be used that way.

I'm not sure about this.  The first hunk of your patch that removes the example
in the top comment block should be valid, as far as I can see at the moment. 
This is because the result of the bitwise not is then again tested for zero
before the conditional jump.
I haven't looked at the details (RTL dumps etc), but looking at the problematic
code in the description, the problem could be that the variable 'condition'
gets the wrong value assigned.  'condition' should have a value of either 0 or
1.  But the sh_treg_combine pass changes the value.  If the conditional jump is
eliminated and the 'condition' value is then added to 'truecount' directly, it
will produce wrong values. 

> As I was unable to find a machine instruction that performs logical
> negation, I prepared a patch that completely removes the parts that rely on
> a logical negate instruction, while keeping all other aspects on the
> optimization pass intact.

Thanks for the patch.  Before completely eliminating the bitwise not insn, I'd
like to do some further analysis and try to keep the bitwise not except for
cases, where it would change the code semantics.

Reply via email to