simplifyCalculations: Improved handling of casts (#4899)