You can use the same C expression for both operands, or different expressions. A digit in constraint is allowed only in an input operand, and it must refer to an output operand. Only a digit in the constraint can guarantee that one operand will be in the same place as another. The mere fact that foo is the value of both operands is not enough to guarantee that they will be in the same place in the generated assembler code. Of course, since the register for operand 1 is not even mentioned in the assembler code, the result will not work, but GNU CC can t tell that.
Some instructions clobber specific hard registers.
If your assembler instruction can alter the condition code register, add cc to the list of clobbered registers. On other machines, the condition code is handled differently, and specifying cc has no effect. But it is valid no matter what the machine. If your assembler instruction modifies memory in an unpredictable fashion, add memory to the list of clobbered registers. This will cause GNU CC to not keep memory values cached in registers across the assembler instruction.