[PATCH] D19338: New code hoisting pass based on GVN (optimistic approach)
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Tue May 17 11:09:10 PDT 2016
majnemer added a subscriber: majnemer.
================
Comment at: llvm/lib/Transforms/Scalar/GVNHoist.cpp:137-152
@@ +136,18 @@
+public:
+ void insert(CallInst *Call, GVN::ValueTable &VN) {
+ if (Call->doesNotReturn() || !Call->doesNotThrow())
+ return;
+
+ // A call that doesNotAccessMemory is handled as a Scalar,
+ // onlyReadsMemory will be handled as a Load instruction,
+ // all other calls will be handled as stores.
+ unsigned V = VN.lookupOrAdd(Call);
+
+ if (Call->doesNotAccessMemory())
+ VNtoCallsScalars.insert(std::make_pair(V, Call));
+ else if (Call->onlyReadsMemory())
+ VNtoCallsLoads.insert(std::make_pair(V, Call));
+ else
+ VNtoCallsStores.insert(std::make_pair(V, Call));
+ }
+
----------------
What if the call is to a function which divides by zero? What would stop you from hoisting the call to it?
================
Comment at: llvm/lib/Transforms/Scalar/GVNHoist.cpp:635-637
@@ +634,5 @@
+ continue;
+ if (!OptForMinSize && !Call->onlyReadsMemory())
+ CallWithSideEffect = true;
+ CI.insert(Call, VN);
+ } else if (!CallWithSideEffect && !isa<GetElementPtrInst>(&I1))
----------------
Likewise, you need to make sure that the call has no side effects which is different from it not mutating memory.
http://reviews.llvm.org/D19338
More information about the llvm-commits
mailing list