Florian Hahn 292077072e
[Local] Treat calls that may not return as being alive.
With the addition of the `willreturn` attribute, functions that may
not return (e.g. due to an infinite loop) are well defined, if they are
not marked as `willreturn`.

This patch updates `wouldInstructionBeTriviallyDead` to not consider
calls that may not return as dead.

This patch still provides an escape hatch for intrinsics, which are
still assumed as willreturn unconditionally. It will be removed once
all intrinsics definitions have been reviewed and updated.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D94106
2021-01-23 16:05:14 +00:00

42 lines
1.2 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -basic-aa -dse -enable-dse-memoryssa=false -S | FileCheck %s
declare i8* @_Znwj(i32) willreturn
declare void @foo() readnone willreturn
define void @test1(i8** %ptr) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: [[VAL:%.*]] = inttoptr i64 23452 to i8*
; CHECK-NEXT: store i8* [[VAL]], i8** [[PTR:%.*]]
; CHECK-NEXT: ret void
;
%val = inttoptr i64 23452 to i8*
store i8* %val, i8** %ptr
%call = call i8* @_Znwj(i32 1)
store i8* %call, i8** %ptr
store i8* %val, i8** %ptr
ret void
}
define void @test2(i8** %ptr, i8* %p1, i8* %p2) {
; CHECK-LABEL: @test2(
; CHECK-NEXT: [[VAL:%.*]] = inttoptr i64 23452 to i8*
; CHECK-NEXT: store i8* [[VAL]], i8** [[PTR:%.*]]
; CHECK-NEXT: call void @foo()
; CHECK-NEXT: store i8* [[P1:%.*]], i8** [[PTR]]
; CHECK-NEXT: call void @foo()
; CHECK-NEXT: store i8* [[VAL]], i8** [[PTR]]
; CHECK-NEXT: ret void
;
%val = inttoptr i64 23452 to i8*
store i8* %val, i8** %ptr
call void @foo()
store i8* %p1, i8** %ptr
call void @foo()
store i8* %p2, i8** %ptr
%call = call i8* @_Znwj(i32 1)
store i8* %call, i8** %ptr
store i8* %val, i8** %ptr
ret void
}