According to the rambam that unlike all other prohibitory mitzvos there are 3 that one must give up one's life for rather than be forced to commit. Does the requirement to give up one's life rather than commit then include suicide if one's has a compulsion to do these three things?
While as far as I know he never addresses this explicitly [i], In all of Rambam's discussion of cardinal sins, he always writes that one allows oneself to be killed (Sefer Hamitsvot Lo Taaseh 63, Hilkhot Yesodei HaTorah 5:2, and Iggeret HaShmad); never that one actively kills himself.
Indeed, suicide is completely forbidden according to Rambam, and he never states any exception to this. For example, in Hilkhot Rotseah (2:2-3) he includes one who commits suicide on a list of those who are considered murderers who are liable to death at the hands of heaven.
In fact, even in a case where someone is coercing a Jew to commit one of the non-cardinal sins, if one allows himself to be killed, rather than committing the sin, although this "suicide" is not his direct action, but that of his oppressors, and although it is being done for a noble purpose, Rambam nevertheless writes (Yesodei HaTorah 5:1) that this is a great sin: הרי זה מתחייב בנפשו.
So, if by all indications, even where someone else is coercing you to sin, there is no permission for suicide, a fortiori, when the oppressor coercing one to sin is oneself, there would be no permission to escape through suicide. This would just be murder, and quite possibly be considered a cardinal sin in and of itself.
[i] Given the above, the lack of explicit mention is understandable. Given that it would be an exception to the existing rules he mentions, if he didn't hold of it, there would be no reason to mention it.