You would probably want a diode from regulator output to regulator input or a plain diode with very low forward voltage after output pin... if the input voltage goes below output voltage, the regulator may not be happy. But with diode between output and input, then voltage from battery would go back into the mosfets and mess things up.
An ideal diode after the output capacitor of the regulator would probably be easier.
But there's much better parts out there for what you want to accomplish.
For example, look at ideal diodes or OR controllers at distributors like Digikey, Mouser, Farnell/Newark, RS-Components etc
OR Controllers, Ideal Diodes :
https://www.digikey.com/en/products/filter/power-management-pmic/or-controllers-ideal-diodes/758some examples of 2 input > 1 output :
TPS2115PW AUTOSWITCHING POWER MULTIPLEXER
TSSOP :
https://www.digikey.com/en/products/detail/texas-instruments/TPS2115PW/5260428SON :
https://www.digikey.com/en/products/detail/texas-instruments/TPS2115ADRBR/1843509datasheet
https://www.ti.com/lit/ds/symlink/tps2114.pdfThe TPS211x family of power multiplexers enables seamless transition between two power supplies, such as a
battery and a wall adapter, each operating at 2.8-5.5 V and delivering up to 1 A. The TPS211x family includes
extensive protection circuitry, including user-programmable current limiting, thermal protection, inrush current
control, seamless supply transition, cross-conduction blocking, and reverse-conduction blocking. These features
greatly simplify designing power multiplexer applications
ICL7673CPAZ (this one's even available in DIP8 package) :
SOIC
https://www.digikey.com/en/products/detail/renesas-electronics-america-inc/ICL7673CBAZA-T/1034565DIP
https://www.digikey.com/en/products/detail/renesas-electronics-america-inc/ICL7673CPAZ/936255https://www.renesas.com/us/en/document/dst/icl7673-datasheetThe Intersil ICL7673 is a monolithic CMOS battery backup circuit that offers unique performance advantages over conventional means of switching to a backup supply. The
ICL7673 is intended as a low-cost solution for the switching of systems between two power supplies; main and battery backup. The main application is keep-alive-battery power
switching for use in volatile CMOS RAM memory systems and real time clocks. In many applications this circuit will represent a low insertion voltage loss between the supplies
and load. This circuit features low current consumption, wide operating voltage range, and exceptionally low leakage between inputs. Logic outputs are provided that can be used
to indicate which supply is connected and can also be used to increase the power switching capability of the circuit by driving external PNP transistors.
Some examples of ideal diodes
LMLM66100 5.5-V, 1.5-A 79-mΩ, Low IQ Ideal Diode With Input Polarity Protection :
https://www.digikey.com/en/products/detail/texas-instruments/LM66100DCKT/10273182datasheet:
https://www.ti.com/lit/ds/symlink/lm66100.pdfThe chip enable works by comparing the CE pin voltage to the input voltage. When the CE pin voltage is higher than VIN, the device is disabled and the MOSFET is off. When the CE pin voltage is lower,
the MOSFET is on. The LM66100 also comes with reverse polarity protection (RPP) that can protect the device from a miswired input, such as a reversed battery.
or
MAX40200 Ultra-Tiny Micropower, 1A Ideal Diode with Ultra-Low Voltage Drop :
https://www.digikey.com/en/products/detail/analog-devices-inc-maxim-integrated/MAX40200AUK-T/7392218The MAX40200 is an ideal diode current-switch that drops so little voltage that it approaches an order of magnitude better than Schottky diodes. When forward-biased and enabled, the MAX40200
conducts with as little as 85mV of voltage drop while carrying currents as high as 1A. Typical voltage drop is 43mV at 500mA, with the voltage drop increasing linearly at higher currents. The MAX40200 thermally protects itself, and any downstream circuitry, from overtemperature conditions. When disabled (EN = low) the MAX40200 blocks voltages up to 6V in either direction, making it suitable for most
low-voltage, portable electronic devices.
Also.... if you can use something better than 1117, some 1117 regulators (depends on manufacturer) will be unstable if the output capacitor doesn't have ESR within a specific range, for example most often that range is 0.1 ohm and 1 ohm, so those particular models will be unstable with ceramic capacitors (unless you add a 0.1ohm or higher resistor in series with the output capacitor.