Files
clang-p2996/llvm/test/Transforms/CodeGenPrepare/X86/delete-assume-dead-code.ll
Jann Horn 91c9dee3fb [CodeGenPrepare] Eliminate llvm.expect before removing empty blocks
CodeGenPrepare currently first removes empty blocks, then in a loop
performs other optimizations. One of those optimizations is the removal
of call instructions that invoke @llvm.assume, which can create new
empty blocks.

This means that when a branch only contains a call to __builtin_assume(),
the empty branch will survive into MIR, and will then only be
half-removed by MIR-level optimizations (e.g. removing the branch but
leaving the condition intact).

Fix it by eliminating @llvm.expect builtin calls before removing empty
blocks.

Reviewed By: bkramer

Differential Revision: https://reviews.llvm.org/D97848
2021-03-04 14:48:26 +01:00

31 lines
893 B
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -codegenprepare -S -mtriple=x86_64-linux < %s | FileCheck %s
define i32 @test1(i8* %d) nounwind {
; CHECK-LABEL: @test1(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[L:%.*]] = load i8, i8* [[D:%.*]], align 1
; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i8 [[L]], 0
; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[TMP0]] to i32
; CHECK-NEXT: ret i32 [[CONV]]
;
entry:
%l = load i8, i8* %d
%cmp = icmp eq i8 %l, 0
br i1 %cmp, label %exit, label %if.end
if.end:
%gep = getelementptr i8, i8* %d, i32 42
%call = call i64 @foo(i8* %gep) nounwind readonly willreturn
%cmp2 = icmp ne i64 %call, 0
call void @llvm.assume(i1 %cmp2)
br label %exit
exit:
%conv = zext i1 %cmp to i32
ret i32 %conv
}
declare i64 @foo(i8*) nounwind readonly willreturn
declare void @llvm.assume(i1 noundef) nounwind willreturn