There are many sayings that invert the word order to convey a different meaning.
- "Do you live to work or do you work to live?"
- "He who fails to plan, plans to fail"
Is there a name for this type of saying?
Antimetabole is I think what you’re after:
In rhetoric, antimetabole … is the repetition of words in successive clauses, but in transposed grammatical order (e.g., "I know what I like, and I like what I know"). It is similar to chiasmus although chiasmus does not use repetition of the same words or phrases.
It's properly called antimetabole — see the linked page for other examples.
Though I have to say that I've never heard of this term before. The more usual (if you want to call it that) term is chiasmus, although properly that just means a sentence (or longer grammatical unit) that uses a parallel form without necessarily repeating the same words.
Antimetabole is the word for this. Quoting from Wheeler,
ANTIMETABOLE (Greek, "turning about"): A rhetorical scheme involving repetition in reverse order: "One should eat to live, not live to eat." Or, "You like it; it likes you." The witches in that Scottish play chant, "Fair is foul and foul is fair." One character in Love's Labor's Lost uses antimetabole when he asks "I pretty, and my saying apt? Or I apt, and my saying pretty?" (I, ii). Antimetabole often overlaps with chiasmus. This device is also called epanados. See schemes.
Note, while chiasmus is nicely related to antimetabole, epanados really is no more antimetabole than are any of antanaclasis, "the stylistic trope of repeating a single word, but with a different meaning each time", or ploce, "a figure of speech in which a word is separated or repeated by way of emphasis; the repetition of a word functioning as a different part of speech or in different contexts" or conduplicatio, "the repetition of a word in various places throughout a paragraph". Antimetabole is slightly related to anadiplosis, "the repetition of the last word of a preceding clause" via the y repetition in the x y y x pattern of antimetabole.