Don Cheadle as Miles Davis in upcoming movie "Miles Ahead." (Brian Douglas/Sony Pictures Classics)

The ghost of Miles Davis has been haunting Don Cheadle for almost 20 years. But the actor — who learned to play the trumpet for his starring role in the new biopic “Miles Ahead” and who bears an uncanny resemblance to the pioneering jazz musician — has been running from it most of that time.

It was during the filming of the 1998 TV movie “The Rat Pack,” in which Cheadle portrayed dancer, singer, actor and drummer Sammy Davis Jr., that the idea of playing Davis first came up. After asking a musician friend to help him find someone to set up a practice drum kit, Cheadle was surprised to see Albert “Tootie” Heath at his door. The veteran percussionist, who has backed up everyone from Nina Simone to Herbie Hancock, first played with Davis as a teenager in Philadelphia.

“He comes in, he’s tuning my drums and he goes, ‘Hey, man, have you ever thought about playing Miles Davis?’ I was like, ‘No, I never thought about it.’ He goes, ‘You guys favor [each other]. There’s something going on. I really think you should.’ ”

In Washington recently to promote his new film, Cheadle recalls that he put no stock in Heath’s comment. Over a 30-year career in which he’s played such historical figures as basketball player Earl “The Goat” Manigault (“Rebound”), humanitarian Paul Rusesabagina (“Hotel Rwanda”) and D.C. talk show host Petey Greene (“Talk to Me”) — not to mention abolitionist Frederick Douglass on an episode of “Drunk History” — the 51-year-old actor had grown weary of impersonating real people. That’s partly because of the conventional structure of many movie biographies, which all too often settle for dutiful litanies of the milestones in a messy life. Those projects, he says, feel like “checking off boxes.”

“I didn’t want any part of it,” Cheadle says of a biopic of Davis, who died in 1991 at age 65. But there were many years of rumored interest, fed by what the actor calls the “grapevine” of Davis’s music peers. Cheadle’s name was first publicly mentioned in connection with the role in 2006 at the jazzman’s induction into the Rock and Roll Hall of Fame. Drummer and producer Vince Wilburn, who is also Davis’s nephew, told reporters, “Don Cheadle’s going to play Miles Davis.”

Don Cheadle during a stop in D.C. (Eli Meir Kaplan/for The Washington Post)

That was news to Cheadle.

Nevertheless, he agreed to hear Wilburn’s pitch. It didn’t go well. The actor opened up about his reluctance, and he told Wilburn that the movie idea sounded too much like the “CliffsNotes version” he was trying to avoid.

“I said, ‘I don’t think it would be a great idea to do a movie about your uncle’s life in that way.’ I’ve read commentary where Miles said — about other movies that he’d seen about artists that were made in that way — he’s had very ‘Miles Davis’ things to say about them, meaning, not kind. I think it would be an affront to him.”

Cheadle made a counterproposal, offering a take that would be truer to the restless creative spirit of Davis, who struggled with addiction and abused his wife, even as he was making some of the most beautiful and groundbreaking music of his time: “It’s got to be gangster. It’s got to be wild. It’s got to be tumultuous and crazy. It’s got to feel like we’re in his head. I want to walk around inside his head. I said, ‘I want to do Don Cheadle is Miles Davis, as Miles Davis. I want to do a movie that Miles Davis would want to star in.’ ”

That movie became “Miles Ahead” — Cheadle’s feature debut as a director.

Written with Steve Baigelman (who shared a story credit on the 2014 James Brown biopic “Get on Up”), the story is framed as a 1979 interview with a music writer (Ewan McGregor) investigating Davis’s five-year hiatus from recording between 1975 and 1980, during which the musician wallowed in drugs, alcohol and sex. Presented as Davis’s somewhat addled version of that period, the movie jumps back and forth between 1979 — as Davis fights with Columbia Records over a mysterious session tape that neither party wants the other to have — and the late ’50s and ’60s, during Davis’s courtship of and stormy 10-year marriage to his first wife, Frances Taylor. Played by Emayatzy Corinealdi, Frances ultimately walks out on her husband, after getting slugged once too often.

Cheadle acknowledges that a portrait of such high contrasts can be hard to bring into focus. (“I was born modal,” Davis says in the film, by way of justifying his volatile nature.) That difficulty applies not only to the audience, but also to the writer and director — in a screenplay that can feel, Cheadle says, “like shifting tectonic plates, under an earthquake about to erupt.” The challenge is even greater for the actor playing the earthquake. Yet Cheadle, who wears all three hats here, says that such mutability comes naturally.

Don Cheadle portrays Miles Davis during a drug-and-sex-filled hiatus between 1985 and 1980 in "Miles Ahead." (Brian Douglas/Sony Pictures Classics)

“I’ve always tried to work in that way, and have these characters be as elastic as they could possibly be,” he says. Speaking of his breakout performance as the hit man Mouse in 1995’s “Devil in a Blue Dress,” Cheadle says he tried to connect to something besides menace in that character. “If the dude’s a sociopath, I want to find the place where you’re laughing with him, and go, like, ‘F---, I’m laughing with this sociopath.’ ”

The same applies to characters such as Rusesabagina in the Oscar-nominated “Hotel Rwanda.” Cheadle argues that the apparent selflessness of the hero, a Rwandan hotel manager who saved more than 1,000 refugees from genocidal militiamen, also can be seen as a selfish desire to protect his own reputation. “I don’t think they’re ‘buts,’ ” Cheadle says of these seeming contradictions. “I think they’re ‘ands.’ ”

The filmmaker knows that the way he has chosen to tell Davis’s story won’t appeal to everyone. Much has been left out, including Davis’s infamous 1957 confrontation with bandmate John Coltrane, whom Davis punched out for playing while high. And the film’s nonlinear structure frequently defies both logic and expectation. It’s human nature, Cheadle says, to be able to hold two contradictory thoughts at the same time, but “we don’t all do it successfully.”

Case in point: The film’s epilogue features Cheadle as Davis jamming — the playing is by Keyon Harrold, the film’s trumpet double — with a band that features such jazz superstars as saxophonist Wayne Shorter, who played for many years with the Miles Davis Quintet, and ­Grammy-winning 31-year-old bassist Esperanza Spalding. The scene is not meant to be taken literally. Proof of that can be seen on Davis’s jacket, which bears the words #SocialMusic (a term that Davis, in the movie, says he prefers to the word “jazz.”)

Cheadle admits to being slightly dismayed that some critics have taken issue with the use of the hashtag and have ignored a more poetic — or jazzy — interpretation: According to Cheadle, the scene represents a literal “dream band,” featuring the ghost (or undying spirit) of Miles Davis, playing with the past, present and future of jazz. After all, the movie ends with the on-screen title “May 26, 1926” — Davis’s birthday — with no end date.

“I thought it was kind of obvious,” says Cheadle, who sums up the philosophy underlying this mind- and ear-bending movie with a mantra that’s suitable for a bumper sticker, as well as a form of religious devotion: “What Would Miles Davis Do?”

Miles Ahead (R, 100 minutes). Opens April 8 at area theaters.