[llvm-branch-commits] [llvm] 070af1b - [InstCombine] avoid crashing on attribute propagation

Sanjay Patel via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 21 05:18:06 PST 2021


Author: Sanjay Patel
Date: 2021-01-21T08:13:26-05:00
New Revision: 070af1b7887f80383d8473bb4da565edbde6c6b0

URL: https://github.com/llvm/llvm-project/commit/070af1b7887f80383d8473bb4da565edbde6c6b0
DIFF: https://github.com/llvm/llvm-project/commit/070af1b7887f80383d8473bb4da565edbde6c6b0.diff

LOG: [InstCombine] avoid crashing on attribute propagation

In https://llvm.org/PR48810 , we are crashing while trying to
propagate attributes from mempcpy (returns void*) to memcpy
(returns nothing - void).

We can avoid the crash by removing known incompatible
attributes for the void return type.

I'm not sure if this goes far enough (should we just drop all
attributes since this isn't the same function?). We also need
to audit other transforms in LibCallSimplifier to make sure
there are no other cases that have the same problem.

Differential Revision: https://reviews.llvm.org/D95088

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
    llvm/test/Transforms/InstCombine/mempcpy.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 99b28b0a832c..b68e45363811 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1150,7 +1150,12 @@ Value *LibCallSimplifier::optimizeMemPCpy(CallInst *CI, IRBuilderBase &B) {
   // mempcpy(x, y, n) -> llvm.memcpy(align 1 x, align 1 y, n), x + n
   CallInst *NewCI =
       B.CreateMemCpy(Dst, Align(1), CI->getArgOperand(1), Align(1), N);
+  // Propagate attributes, but memcpy has no return value, so make sure that
+  // any return attributes are compliant.
+  // TODO: Attach return value attributes to the 1st operand to preserve them?
   NewCI->setAttributes(CI->getAttributes());
+  NewCI->removeAttributes(AttributeList::ReturnIndex,
+                          AttributeFuncs::typeIncompatible(NewCI->getType()));
   return B.CreateInBoundsGEP(B.getInt8Ty(), Dst, N);
 }
 

diff  --git a/llvm/test/Transforms/InstCombine/mempcpy.ll b/llvm/test/Transforms/InstCombine/mempcpy.ll
index 79158a3a0a6d..61e7ec4a3339 100644
--- a/llvm/test/Transforms/InstCombine/mempcpy.ll
+++ b/llvm/test/Transforms/InstCombine/mempcpy.ll
@@ -53,4 +53,15 @@ define i8* @memcpy_big_const_n(i8* %d, i8* nocapture readonly %s) {
   ret i8* %r
 }
 
+; The original call may have attributes that can not propagate to memcpy.
+
+define i32 @PR48810() {
+; CHECK-LABEL: @PR48810(
+; CHECK-NEXT:    call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 undef, i8* align 536870912 null, i64 undef, i1 false)
+; CHECK-NEXT:    ret i32 undef
+;
+  %r = call dereferenceable(1) i8* @mempcpy(i8* undef, i8* null, i64 undef)
+  ret i32 undef
+}
+
 declare i8* @mempcpy(i8*, i8* nocapture readonly, i64)


        


More information about the llvm-branch-commits mailing list