[llvm] r273777 - [InstSimplify] Replace calls to null with undef

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 25 00:37:30 PDT 2016


Author: majnemer
Date: Sat Jun 25 02:37:30 2016
New Revision: 273777

URL: http://llvm.org/viewvc/llvm-project?rev=273777&view=rev
Log:
[InstSimplify] Replace calls to null with undef

Calling null is undefined behavior, we can simplify the resulting value
to undef.

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/test/Transforms/InstSimplify/call.ll

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=273777&r1=273776&r2=273777&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Sat Jun 25 02:37:30 2016
@@ -4009,7 +4009,8 @@ static Value *SimplifyCall(Value *V, Ite
   FunctionType *FTy = cast<FunctionType>(Ty);
 
   // call undef -> undef
-  if (isa<UndefValue>(V))
+  // call null -> undef
+  if (isa<UndefValue>(V) || isa<ConstantPointerNull>(V))
     return UndefValue::get(FTy->getReturnType());
 
   Function *F = dyn_cast<Function>(V);

Modified: llvm/trunk/test/Transforms/InstSimplify/call.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/call.ll?rev=273777&r1=273776&r2=273777&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/call.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/call.ll Sat Jun 25 02:37:30 2016
@@ -187,4 +187,20 @@ cast.end:
 ; CHECK: br i1 %cmp, label %cast.end, label %cast.notnull
 }
 
+define i32 @call_null() {
+entry:
+  %call = call i32 null()
+  ret i32 %call
+}
+; CHECK-LABEL: define i32 @call_null(
+; CHECK: ret i32 undef
+
+define i32 @call_undef() {
+entry:
+  %call = call i32 undef()
+  ret i32 %call
+}
+; CHECK-LABEL: define i32 @call_undef(
+; CHECK: ret i32 undef
+
 declare noalias i8* @malloc(i64)




More information about the llvm-commits mailing list