On 9/1/23 06:13, Jeff Law wrote: >> I could very well be mistaken, but define_insn is a pattern match and >> opt2 has *ne* so the expression has to be in != form and thus needs >> to work with that condition. No ? > My point was  that > > x = (a != 0) ? x : 0 > > is equivalent to > > x = (a == 0) ? 0 : x > > You can invert the condition and swap the arms and get the same > semantics.  Thus if one can be supported, so can the other as they're > functionally equivalent. Ah I see what you mean. Indeed the pattern is fine, it just doesn't map to the right asm. So we certainly need a fix but it could just very well be this: (define_insn "*czero.nez..opt2"   [(set (match_operand:GPR 0 "register_operand" "=r")         (if_then_else:GPR (ne (match_operand:X 1 "register_operand" "r")                               (const_int 0))                           (match_operand:GPR 2 "register_operand" "r")                           (match_operand:GPR 3 "register_operand" "1")))]   "TARGET_ZICOND && rtx_equal_p (operands[1], operands[3])" -  "czero.nez\t%0,%2,%1" }  "czero.eqz\t%0,%2,%1" ) > It may be the at we've goof'd something in handling the inverted case, > but conceptually we ought to be able to handle both. Indeed there's a small goof as shown above. > > I don't doubt you've got a failure, but it's also the case that I'm > not seeing the same failure when I turn on zicond and run the > execute.exp tests.  So clearly there's a difference somewhere in what > we're doing. It doesn't show up in execute.exp but as following (perhaps I should add that to commit log too). FAIL: gcc.c-torture/execute/pr60003.c   -O1  execution test FAIL: gcc.dg/setjmp-3.c execution test FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -O1  execution test FAIL: gcc.dg/torture/stackalign/setjmp-3.c   -O1 -fpic execution test > > So perhaps we should start with comparing assembly output for the test > in question.  Can you pass yours along, I'll diff them this afternoon > and see what we find. Attached is slightly modified pr60003.c (to differentiate 'X' and 'a') and the failing asm and with fix (both the deleted pattern and modified pattern produce correct, if slightly different code). Thx, -Vineet