Setting Axis Range Exactly With Variable Bins

You could create and draw an empty histogram, with sufficiently dense x-bins. And then, on top of it, you could draw your “hist” using “same”:

{
  Double_t x[] = {0., 100., 150., 200., 500., 20000.};
  TH1F *hist = new TH1F("hist", "hist title;x axis name;y axis name",
                        ((sizeof(x) / sizeof(Double_t)) - 1), x);
  hist->SetLineColor(kRed);
  hist->Fill(0., 1.); hist->Fill(100., 2.); hist->Fill(150., 3.); hist->Fill(200., 4.); hist->Fill(500., 5.);
  //
  TH1C *h = new TH1C("h", "h", 10000, -1., 1.);
  h->SetStats(kFALSE);
  h->SetTitle(hist->GetTitle());
  h->SetXTitle(hist->GetXaxis()->GetTitle());
  h->SetYTitle(hist->GetYaxis()->GetTitle());
  h->GetXaxis()->SetLimits(hist->GetXaxis()->GetXmin(),
                           hist->GetXaxis()->GetXmax());
  h->SetMinimum(hist->GetMinimum());
  h->SetMaximum(hist->GetMaximum());
  //
  h->GetXaxis()->SetRangeUser(0., 1000.);
  h->Draw();
  hist->Draw("SAMES");
}