]> granicus.if.org Git - llvm/commitdiff
[InstSimplify] Replace calls to null with undef
authorDavid Majnemer <david.majnemer@gmail.com>
Sat, 25 Jun 2016 07:37:30 +0000 (07:37 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sat, 25 Jun 2016 07:37:30 +0000 (07:37 +0000)
Calling null is undefined behavior, we can simplify the resulting value
to undef.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273777 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/InstructionSimplify.cpp
test/Transforms/InstSimplify/call.ll

index 746b7409dfea0956f4054e31b856f5489bff7196..b52ffeebe616e01076baf3b29228cb3025b59a28 100644 (file)
@@ -4009,7 +4009,8 @@ static Value *SimplifyCall(Value *V, IterTy ArgBegin, IterTy ArgEnd,
   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);
index b360ecb843423d1111375364dc878c2471246c28..814f1f21aca9616983ead04a13d47cc5d304f2e8 100644 (file)
@@ -187,4 +187,20 @@ cast.end:                                         ; preds = %cast.notnull, %entr
 ; 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)