[llvm] r225895 - [SimplifyLibCalls] Don't try to simplify indirect calls.

Ahmed Bougacha ahmed.bougacha at gmail.com
Tue Jan 13 16:55:05 PST 2015


Author: ab
Date: Tue Jan 13 18:55:05 2015
New Revision: 225895

URL: http://llvm.org/viewvc/llvm-project?rev=225895&view=rev
Log:
[SimplifyLibCalls] Don't try to simplify indirect calls.

It turns out, all callsites of the simplifier are guarded by a check for
CallInst::getCalledFunction (i.e., to make sure the callee is direct).

This check wasn't done when trying to further optimize a simplified fortified
libcall, introduced by a refactoring in r225640.

Fix that, add a testcase, and document the requirement.

Modified:
    llvm/trunk/include/llvm/Transforms/Utils/SimplifyLibCalls.h
    llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
    llvm/trunk/test/Transforms/InstCombine/memcpy_chk-1.ll

Modified: llvm/trunk/include/llvm/Transforms/Utils/SimplifyLibCalls.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/SimplifyLibCalls.h?rev=225895&r1=225894&r2=225895&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/SimplifyLibCalls.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/SimplifyLibCalls.h Tue Jan 13 18:55:05 2015
@@ -46,6 +46,7 @@ public:
   /// \brief Take the given call instruction and return a more
   /// optimal value to replace the instruction with or 0 if a more
   /// optimal form can't be found.
+  /// The call must not be an indirect call.
   Value *optimizeCall(CallInst *CI);
 
 private:
@@ -83,6 +84,7 @@ public:
   /// be equal to the instruction being optimized.  In this case all
   /// other instructions that use the given instruction were modified
   /// and the given instruction is dead.
+  /// The call must not be an indirect call.
   Value *optimizeCall(CallInst *CI);
 
   /// replaceAllUsesWith - This method is used when the library call

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=225895&r1=225894&r2=225895&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Tue Jan 13 18:55:05 2015
@@ -1966,7 +1966,8 @@ Value *LibCallSimplifier::optimizeCall(C
   // Also try to simplify calls to fortified library functions.
   if (Value *SimplifiedFortifiedCI = FortifiedSimplifier.optimizeCall(CI)) {
     // Try to further simplify the result.
-    if (CallInst *SimplifiedCI = dyn_cast<CallInst>(SimplifiedFortifiedCI))
+    CallInst *SimplifiedCI = dyn_cast<CallInst>(SimplifiedFortifiedCI);
+    if (SimplifiedCI && SimplifiedCI->getCalledFunction())
       if (Value *V = optimizeStringMemoryLibCall(SimplifiedCI, Builder))
         return V;
     return SimplifiedFortifiedCI;

Modified: llvm/trunk/test/Transforms/InstCombine/memcpy_chk-1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/memcpy_chk-1.ll?rev=225895&r1=225894&r2=225895&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/memcpy_chk-1.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/memcpy_chk-1.ll Tue Jan 13 18:55:05 2015
@@ -57,4 +57,17 @@ define void @test_no_simplify2() {
   ret void
 }
 
+define i8* @test_simplify_return_indcall(i8* ()* %alloc) {
+; CHECK-LABEL: @test_simplify_return_indcall(
+  %src = bitcast %struct.T2* @t2 to i8*
+
+; CHECK-NEXT: %dst = call i8* %alloc()
+  %dst = call i8* %alloc()
+
+; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64
+  %ret = call i8* @__memcpy_chk(i8* %dst, i8* %src, i64 1824, i64 1824)
+; CHECK-NEXT: ret i8* %dst
+  ret i8* %ret
+}
+
 declare i8* @__memcpy_chk(i8*, i8*, i64, i64)





More information about the llvm-commits mailing list