[PATCH] D14797: [BranchFolding] Add volatile checking when clearing memory references

Junmo Park via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 18 17:20:44 PST 2015


flyingforyou created this revision.
flyingforyou added reviewers: apazos, hfinkel, mcrosier.
flyingforyou added a subscriber: llvm-commits.

When tail merging, we remove the MMO from the common tail.
This means we treat merged instruction as volatile.
For avoiding this, we add NonVolatileLdSt variable to check
merged instruction is real volatile or not.

http://reviews.llvm.org/D14797

Files:
  include/llvm/CodeGen/MachineInstr.h
  lib/CodeGen/BranchFolding.cpp
  lib/CodeGen/MachineInstr.cpp

Index: lib/CodeGen/MachineInstr.cpp
===================================================================
--- lib/CodeGen/MachineInstr.cpp
+++ lib/CodeGen/MachineInstr.cpp
@@ -645,7 +645,7 @@
                            DebugLoc dl, bool NoImp)
     : MCID(&tid), Parent(nullptr), Operands(nullptr), NumOperands(0), Flags(0),
       AsmPrinterFlags(0), NumMemRefs(0), MemRefs(nullptr),
-      debugLoc(std::move(dl)) {
+      NonVolatileLdSt(false), debugLoc(std::move(dl)) {
   assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
 
   // Reserve space for the expected number of operands.
@@ -662,10 +662,9 @@
 /// MachineInstr ctor - Copies MachineInstr arg exactly
 ///
 MachineInstr::MachineInstr(MachineFunction &MF, const MachineInstr &MI)
-  : MCID(&MI.getDesc()), Parent(nullptr), Operands(nullptr), NumOperands(0),
-    Flags(0), AsmPrinterFlags(0),
-    NumMemRefs(MI.NumMemRefs), MemRefs(MI.MemRefs),
-    debugLoc(MI.getDebugLoc()) {
+    : MCID(&MI.getDesc()), Parent(nullptr), Operands(nullptr), NumOperands(0),
+      Flags(0), AsmPrinterFlags(0), NumMemRefs(MI.NumMemRefs),
+      MemRefs(MI.MemRefs), NonVolatileLdSt(false), debugLoc(MI.getDebugLoc()) {
   assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
 
   CapOperands = OperandCapacity::get(MI.getNumOperands());
@@ -1442,7 +1441,7 @@
 
   // Otherwise, if the instruction has no memory reference information,
   // conservatively assume it wasn't preserved.
-  if (memoperands_empty())
+  if (!NonVolatileLdSt && memoperands_empty())
     return true;
 
   // Check the memory reference information for ordered references.
Index: lib/CodeGen/BranchFolding.cpp
===================================================================
--- lib/CodeGen/BranchFolding.cpp
+++ lib/CodeGen/BranchFolding.cpp
@@ -793,7 +793,8 @@
 
     if (MBBICommon->mayLoad() || MBBICommon->mayStore())
       if (!hasIdenticalMMOs(&*MBBI, &*MBBICommon))
-        MBBICommon->clearMemRefs();
+        MBBICommon->clearMemRefs(!MBBICommon->hasOrderedMemoryRef() &&
+                                 !MBBI->hasOrderedMemoryRef());
 
     ++MBBI;
     ++MBBICommon;
Index: include/llvm/CodeGen/MachineInstr.h
===================================================================
--- include/llvm/CodeGen/MachineInstr.h
+++ include/llvm/CodeGen/MachineInstr.h
@@ -93,6 +93,7 @@
 
   uint8_t NumMemRefs;                   // Information on memory references.
   mmo_iterator MemRefs;
+  bool NonVolatileLdSt;
 
   DebugLoc debugLoc;                    // Source line information.
 
@@ -1179,9 +1180,10 @@
   }
 
   /// Clear this MachineInstr's memory reference descriptor list.
-  void clearMemRefs() {
+  void clearMemRefs(bool IsNonVolatileLdSt) {
     MemRefs = nullptr;
     NumMemRefs = 0;
+    NonVolatileLdSt = IsNonVolatileLdSt;
   }
 
   /// Break any tie involving OpIdx.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14797.40581.patch
Type: text/x-patch
Size: 2867 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151119/780316de/attachment.bin>


More information about the llvm-commits mailing list