[llvm-branch-commits] [llvm] d042f2d - [InstSimplify] Fold call null/undef to poison

Nikita Popov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jan 6 12:19:59 PST 2021


Author: Nikita Popov
Date: 2021-01-06T21:09:30+01:00
New Revision: d042f2db5bf0a852bdbef53ab0310d363031f56f

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

LOG: [InstSimplify] Fold call null/undef to poison

Calling null or undef results in immediate undefined behavior.
Return poison instead of undef in this case, similar to what
we do for immediate UB due to division by zero.

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp
    llvm/test/Transforms/GVN/PRE/volatile.ll
    llvm/test/Transforms/InstSimplify/call.ll
    llvm/test/Transforms/InstSimplify/undef.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 1304f0e78b29..4de9085e8233 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5690,11 +5690,11 @@ Value *llvm::SimplifyCall(CallBase *Call, const SimplifyQuery &Q) {
   if (Call->isMustTailCall())
     return nullptr;
 
-  // call undef -> undef
-  // call null -> undef
+  // call undef -> poison
+  // call null -> poison
   Value *Callee = Call->getCalledOperand();
   if (isa<UndefValue>(Callee) || isa<ConstantPointerNull>(Callee))
-    return UndefValue::get(Call->getType());
+    return PoisonValue::get(Call->getType());
 
   if (Value *V = tryConstantFoldCall(Call, Q))
     return V;

diff  --git a/llvm/test/Transforms/GVN/PRE/volatile.ll b/llvm/test/Transforms/GVN/PRE/volatile.ll
index fe417e38830f..1a51388723f1 100644
--- a/llvm/test/Transforms/GVN/PRE/volatile.ll
+++ b/llvm/test/Transforms/GVN/PRE/volatile.ll
@@ -204,7 +204,7 @@ define i32 @test9(i32* %V) {
 ; CHECK-LABEL: @test9(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[LOAD:%.*]] = call i32 undef()
-; CHECK-NEXT:    ret i32 undef
+; CHECK-NEXT:    ret i32 poison
 ;
 entry:
   %load = call i32 undef()

diff  --git a/llvm/test/Transforms/InstSimplify/call.ll b/llvm/test/Transforms/InstSimplify/call.ll
index bb7410ada7d5..328626e4d1ce 100644
--- a/llvm/test/Transforms/InstSimplify/call.ll
+++ b/llvm/test/Transforms/InstSimplify/call.ll
@@ -454,7 +454,7 @@ define i32 @call_null() {
 ; CHECK-LABEL: @call_null(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[CALL:%.*]] = call i32 null()
-; CHECK-NEXT:    ret i32 undef
+; CHECK-NEXT:    ret i32 poison
 ;
 entry:
   %call = call i32 null()
@@ -465,7 +465,7 @@ define i32 @call_undef() {
 ; CHECK-LABEL: @call_undef(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[CALL:%.*]] = call i32 undef()
-; CHECK-NEXT:    ret i32 undef
+; CHECK-NEXT:    ret i32 poison
 ;
 entry:
   %call = call i32 undef()

diff  --git a/llvm/test/Transforms/InstSimplify/undef.ll b/llvm/test/Transforms/InstSimplify/undef.ll
index fe40f2ce319e..d09dc43da091 100644
--- a/llvm/test/Transforms/InstSimplify/undef.ll
+++ b/llvm/test/Transforms/InstSimplify/undef.ll
@@ -172,7 +172,7 @@ define i64 @test17(i64 %a) {
 define i64 @test18(i64 %a) {
 ; CHECK-LABEL: @test18(
 ; CHECK-NEXT:    [[R:%.*]] = call i64 undef(i64 [[A:%.*]])
-; CHECK-NEXT:    ret i64 undef
+; CHECK-NEXT:    ret i64 poison
 ;
   %r = call i64 (i64) undef(i64 %a)
   ret i64 %r


        


More information about the llvm-branch-commits mailing list