[PATCH] D70749: [InstCombine] do not insert nonnull assumption for undef

Bob Haarman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 26 16:52:49 PST 2019


inglorion updated this revision to Diff 231153.
inglorion added a comment.

moved undef check above other if statement


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70749/new/

https://reviews.llvm.org/D70749

Files:
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/assume-replacing-call.ll


Index: llvm/test/Transforms/InstCombine/assume-replacing-call.ll
===================================================================
--- llvm/test/Transforms/InstCombine/assume-replacing-call.ll
+++ llvm/test/Transforms/InstCombine/assume-replacing-call.ll
@@ -183,6 +183,30 @@
   ret i32 %retval.0
 }
 
+define i64 @test_sink_undef(i1 %c, i64 %x) {
+; Check that we don't insert a nonnull assumption for undef.
+; CHECK-LABEL: @test_sink_undef(
+; CHECK-NEXT: entry:
+; CHECK-NOT:    @llvm.assume(
+; CHECK:        br i1 %c, label %ctrue, label %cend
+; CHECK:      ctrue:
+; CHECK-NEXT:   %foo = call i64 @func_test_nonnull(i8* undef)
+; CHECK-NEXT:   br label %cend
+; CHECK:      cend:
+; CHECK-NEXT:   %retval = phi i64 [ %x, %entry ], [ %foo, %ctrue ]
+; CHECK-NEXT:   ret i64 %retval
+entry:
+  %foo = call i64 @func_test_nonnull(i8* undef) #2
+  br i1 %c, label %ctrue, label %cend
+
+ctrue:
+  br label %cend
+
+cend:
+  %retval = phi i64 [%x, %entry], [%foo, %ctrue]
+  ret i64 %retval
+}
+
 declare i64 @func_test(i8* %0) #1
 
 declare i64 @func_test_nonnull(i8* nonnull %0) #3
Index: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -3186,18 +3186,19 @@
   // If this instruction was providing nonnull guarantees insert assumptions for
   // nonnull call site arguments.
   if (auto CS = dyn_cast<CallBase>(I)) {
-    for (unsigned Idx = 0; Idx != CS->getNumArgOperands(); Idx++)
+    for (unsigned Idx = 0; Idx != CS->getNumArgOperands(); Idx++) {
+      Value *V = CS->getArgOperand(Idx);
+      if (isa<UndefValue>(*V))
+        continue;
       if (CS->paramHasAttr(Idx, Attribute::NonNull) ||
           (CS->paramHasAttr(Idx, Attribute::Dereferenceable) &&
            !llvm::NullPointerIsDefined(CS->getFunction(),
-                                       CS->getArgOperand(Idx)
-                                           ->getType()
-                                           ->getPointerAddressSpace()))) {
-        Value *V = CS->getArgOperand(Idx);
-
+                                       V->getType()
+                                         ->getPointerAddressSpace()))) {
         Builder.SetInsertPoint(I->getParent(), I->getIterator());
         Builder.CreateAssumption(Builder.CreateIsNotNull(V));
       }
+    }
   }
 
   BasicBlock::iterator InsertPos = DestBlock->getFirstInsertionPt();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70749.231153.patch
Type: text/x-patch
Size: 2526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191127/bca3bf33/attachment.bin>


More information about the llvm-commits mailing list