We study the low-energy limit of a compactification of N=4 U(n) super
Yang-Mills theory on S1 with boundary conditions modified by an S-duality
and R-symmetry twist. This theory has N=6 supersymmetry in 2+1D. We analyze the
T2 compactification of this 2+1D theory by identifying a dual weakly coupled
type-IIA background. The Hilbert space of normalizable ground states is
finite-dimensional and appears to exhibit a rich structure of sectors. We
identify most of them with Hilbert spaces of Chern-Simons theory (with
appropriate gauge groups and levels). We also discuss a realization of a
related twisted compactification in terms of the (2,0)-theory, where the recent
solution by Gaiotto and Witten of the boundary conditions describing D3-branes
ending on a (p,q) 5-brane plays a crucial role.Comment: 104 pages, 5 figures. Revisions to subsection (6.6) and other minor
corrections included in version