A digital signal processor (DSP) has a specific architecture to process multimedia data very fast, but its complexity makes it difficult that a compiler generates highly optimized codes. A mode set problem is one of these difficulties. A mode set in DSP architectures provides extended functionalities to an instruction. The instruction performs differently depending on the mode set. In this paper, we propose a code optimization technique to eliminate redundant mode set instructions. For our purpose, we introduce a dataflow analysis for the mode set optimization based on a control flow graph. The proposed algorithm guarantees that the dynamic number of mode set instructions is minimal. As an experiment, we applied our algorithm to a sign extension mode (SXM) in the Zaram compactDSP 16 architecture, and we could eliminate redundant mode set instructions by 50% on average and up to 93% in our measured benchmarks.