[llvm] r337785 - [x86/SLH] Simplify the code for hardening a loaded value. NFC.
Chandler Carruth via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 23 17:35:36 PDT 2018
Author: chandlerc
Date: Mon Jul 23 17:35:36 2018
New Revision: 337785
URL: http://llvm.org/viewvc/llvm-project?rev=337785&view=rev
Log:
[x86/SLH] Simplify the code for hardening a loaded value. NFC.
This is in preparation for extracting this into a re-usable utility in
this code.
Modified:
llvm/trunk/lib/Target/X86/X86SpeculativeLoadHardening.cpp
Modified: llvm/trunk/lib/Target/X86/X86SpeculativeLoadHardening.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86SpeculativeLoadHardening.cpp?rev=337785&r1=337784&r2=337785&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86SpeculativeLoadHardening.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86SpeculativeLoadHardening.cpp Mon Jul 23 17:35:36 2018
@@ -1884,35 +1884,30 @@ void X86SpeculativeLoadHardeningPass::ha
auto *DefRC = MRI->getRegClass(OldDefReg);
int DefRegBytes = TRI->getRegSizeInBits(*DefRC) / 8;
- unsigned OrOpCodes[] = {X86::OR8rr, X86::OR16rr, X86::OR32rr, X86::OR64rr};
- unsigned OrOpCode = OrOpCodes[Log2_32(DefRegBytes)];
-
- unsigned SubRegImms[] = {X86::sub_8bit, X86::sub_16bit, X86::sub_32bit};
-
- auto GetStateRegInRC = [&](const TargetRegisterClass &RC) {
- unsigned StateReg = PS->SSA.GetValueAtEndOfBlock(&MBB);
+ unsigned StateReg = PS->SSA.GetValueAtEndOfBlock(&MBB);
- int Bytes = TRI->getRegSizeInBits(RC) / 8;
- // FIXME: Need to teach this about 32-bit mode.
- if (Bytes != 8) {
- unsigned SubRegImm = SubRegImms[Log2_32(Bytes)];
- unsigned NarrowStateReg = MRI->createVirtualRegister(&RC);
- BuildMI(MBB, MI.getIterator(), Loc, TII->get(TargetOpcode::COPY),
- NarrowStateReg)
- .addReg(StateReg, 0, SubRegImm);
- StateReg = NarrowStateReg;
- }
- return StateReg;
- };
+ // FIXME: Need to teach this about 32-bit mode.
+ if (DefRegBytes != 8) {
+ unsigned SubRegImms[] = {X86::sub_8bit, X86::sub_16bit, X86::sub_32bit};
+ unsigned SubRegImm = SubRegImms[Log2_32(DefRegBytes)];
+ unsigned NarrowStateReg = MRI->createVirtualRegister(DefRC);
+ BuildMI(MBB, MI.getIterator(), Loc, TII->get(TargetOpcode::COPY),
+ NarrowStateReg)
+ .addReg(StateReg, 0, SubRegImm);
+ StateReg = NarrowStateReg;
+ }
auto InsertPt = std::next(MI.getIterator());
+
unsigned FlagsReg = 0;
if (isEFLAGSLive(MBB, InsertPt, *TRI))
FlagsReg = saveEFLAGS(MBB, InsertPt, Loc);
- unsigned StateReg = GetStateRegInRC(*DefRC);
unsigned NewDefReg = MRI->createVirtualRegister(DefRC);
DefOp.setReg(NewDefReg);
+
+ unsigned OrOpCodes[] = {X86::OR8rr, X86::OR16rr, X86::OR32rr, X86::OR64rr};
+ unsigned OrOpCode = OrOpCodes[Log2_32(DefRegBytes)];
auto OrI = BuildMI(MBB, InsertPt, Loc, TII->get(OrOpCode), OldDefReg)
.addReg(StateReg)
.addReg(NewDefReg);
More information about the llvm-commits
mailing list