I reviewed the Tamron lens here -
http://www.bobatkins.com/photography/reviews/tamron_17-50_VC_review.html.
It's pretty good optically, it's faster the Canon lens and it has image stabilization. Those are it's positive features. On the other hand the Canon lens covers full frame and is also optically good. It's also weathersealed, but that's only really effective if used with a weathersealed camera.
I think if I knew I was going to stick with crop sensor cameras like the 40D (or 7D), then I'd probably lean towards the
Tamron 17-50/2.8 VC based on the wider focal length range and the image stabilization. It's also $100 cheaper.
On the other hand if I thought I might be adding a full frame body to my kit at some point, then I'd lean towards the
Canon EF 17-40/4L based on it's ability to be used with both crop sensor and full frame cameras.