hlsl shader optimization

I’ve updated the original post with my current shader.
There are no loops anymore but there’s an additional boolean value for the font shadow. How would I use ddx and ddy to get the texelsize?