A compound of formula, or a pharmaceutically acceptable salt thereof: wherein: m is 0, 1, 2, 3, 4 or 5; p is 0, 1, 2, 3, 4 or 5; each occurrence of W is independently selected from (a) --- CR a R b -, (b) -NR a -, (c) -C - and (d) -O-(CR a R b) r -; wherein r is 1, 2 or 3; each occurrence of R a and R b is independently selected from the group consisting of (a) hydrogen, (b) halogen and (c) C 1-6 alkyl, optionally substituted with 1 to 3 halogens; X is selected from -NR c -, -S- and -O-; R c is selected from (a) hydrogen and (b) C 1-6 alkyl; " --- " is an optional double bond; provided that when " --- " is a double bond, then the W attached to the double bond is =CR a — and one R 2 on the adjacent carbon is absent; each occurrence of R 1 is independently selected from the group consisting of (a) hydrogen, (b) halogen, (c) -CN, (d) C 1-6 alkyl, optionally substituted with 1 to 3 halogens, (e) C 3-6 cycloalkyl, (f) OCHF 2, (g) OCF 3, (h) SCF 3, and (i) SF 5; each occurrence of R 2 is independently selected from the group consisting of (a) hydrogen, (b) halogen, (c) -OH and (d) C 1-6 alkyl, optionally substituted with 1 to 3 halogens; or two R 2 groups together with the carbon to which they are attached form a C 3-6 cycloakyl or a 4-, 5-, or 6-membered heterocycle; or R 2 and R 5 together with the carbon and sulfur atoms to which they are attached form a 4-, 5- or 6-membered heterocycle; or R 2 and R a of W together with the carbon and/or nitrogen atoms to which they are attached form (a) a 4-, 5- or 6-membered carbocycle, (b) a 7-8 membered spiro bicyclic carbocyclyl, (c) a 7-8 membered spiro bicyclic heterocycle, (d) a 5-6 membered bridged bicyclic carbocyclyl, or (e) a 4-, 5- or 6-membered heterocycle; R 4 is selected from the group consisting of (a) hydrogen and (b) C 1-6 alkyl; R 5 is selected from the group consisting of (a) C 1-6 alkyl optionally substituted with -OH, (b) C 3-6 cycloalkyl, (c) aryl and (d) 4-, 5- or 6-membered heterocycle; and R 6 is selected from the group consisting of (a) hydrogen, (b) -CN, (c) -C -NH 2, (d) C 1-6 alkyl opyionally substituted with -OH and (e) -O-C 1-6 alkyl. m is 0, 1, 2, 3, 4 or 5; p is 0, 1, 2, 3, 4 or 5; each occurrence of W is independently selected from (a) --- CR a R b -, (b) -NR a -, (c) -C - and (d) -O-(CR a R b) r -; wherein r is 1, 2 or 3; each occurrence of R a and R b is independently selected from the group consisting of (a) hydrogen, (b) halogen and (c) C 1-6 alkyl, optionally substituted with 1 to 3 halogens; X is selected from -NR c -, -S- and -O-; R c is selected from (a) hydrogen and (b) C 1-6 alkyl; " --- " is an optional double bond; provided that when " --- " is a double bond, then the W attached to the double bond is =CR a — and one R 2 on the adjacent carbon is absent; each occurrence of R 1 is independently selected from the group consisting of (a) hydrogen, (b) halogen, (c) -CN, (d) C 1-6 alkyl, optionally substituted with 1 to 3 halogens, (e) C 3-6 cycloalkyl, (f) OCHF 2, (g) OCF 3, (h) SCF 3, and (i) SF 5; each occurrence of R 2 is independently selected from the group consisting of (a) hydrogen, (b) halogen, (c) -OH and (d) C 1-6 alkyl, optionally substituted with 1 to 3 halogens; or two R 2 groups together with the carbon to which they are attached form a C 3-6 cycloakyl or a 4-, 5-, or 6-membered heterocycle; or R 2 and R 5 together with the carbon and sulfur atoms to which they are attached form a 4-, 5- or 6-membered heterocycle; or R 2 and R a of W together with the carbon and/or nitrogen atoms to which they are attached form (a) a 4-, 5- or 6-membered carbocycle, (b) a 7-8 membered spiro bicyclic carbocyclyl, (c) a 7-8 membered spiro bicyclic heterocycle, (d) a 5-6 membered bridged bicyclic carbocyclyl, or (e) a 4-, 5- or 6-membered heterocycle; R 4 is selected from the group consisting of (a) hydrogen and (b) C 1-6 alkyl; R 5 is selected from the group consisting of (a) C 1-6 alkyl optionally substituted with -OH, (b) C 3-6 cycloalkyl, (c) aryl and (d) 4-, 5- or 6-membered heterocycle; and R 6 is selected from the group consisting of (a) hydrogen, (b) -CN, (c) -C -NH 2, (d) C 1-6 alkyl opyionally substituted with -OH and (e) -O-C 1-6 alkyl.