Skip to content

Commit d042f2d

Browse files
committed
[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.
1 parent 7d48eff commit d042f2d

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5690,11 +5690,11 @@ Value *llvm::SimplifyCall(CallBase *Call, const SimplifyQuery &Q) {
56905690
if (Call->isMustTailCall())
56915691
return nullptr;
56925692

5693-
// call undef -> undef
5694-
// call null -> undef
5693+
// call undef -> poison
5694+
// call null -> poison
56955695
Value *Callee = Call->getCalledOperand();
56965696
if (isa<UndefValue>(Callee) || isa<ConstantPointerNull>(Callee))
5697-
return UndefValue::get(Call->getType());
5697+
return PoisonValue::get(Call->getType());
56985698

56995699
if (Value *V = tryConstantFoldCall(Call, Q))
57005700
return V;

llvm/test/Transforms/GVN/PRE/volatile.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ define i32 @test9(i32* %V) {
204204
; CHECK-LABEL: @test9(
205205
; CHECK-NEXT: entry:
206206
; CHECK-NEXT: [[LOAD:%.*]] = call i32 undef()
207-
; CHECK-NEXT: ret i32 undef
207+
; CHECK-NEXT: ret i32 poison
208208
;
209209
entry:
210210
%load = call i32 undef()

llvm/test/Transforms/InstSimplify/call.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ define i32 @call_null() {
454454
; CHECK-LABEL: @call_null(
455455
; CHECK-NEXT: entry:
456456
; CHECK-NEXT: [[CALL:%.*]] = call i32 null()
457-
; CHECK-NEXT: ret i32 undef
457+
; CHECK-NEXT: ret i32 poison
458458
;
459459
entry:
460460
%call = call i32 null()
@@ -465,7 +465,7 @@ define i32 @call_undef() {
465465
; CHECK-LABEL: @call_undef(
466466
; CHECK-NEXT: entry:
467467
; CHECK-NEXT: [[CALL:%.*]] = call i32 undef()
468-
; CHECK-NEXT: ret i32 undef
468+
; CHECK-NEXT: ret i32 poison
469469
;
470470
entry:
471471
%call = call i32 undef()

llvm/test/Transforms/InstSimplify/undef.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ define i64 @test17(i64 %a) {
172172
define i64 @test18(i64 %a) {
173173
; CHECK-LABEL: @test18(
174174
; CHECK-NEXT: [[R:%.*]] = call i64 undef(i64 [[A:%.*]])
175-
; CHECK-NEXT: ret i64 undef
175+
; CHECK-NEXT: ret i64 poison
176176
;
177177
%r = call i64 (i64) undef(i64 %a)
178178
ret i64 %r

0 commit comments

Comments
 (0)