Files
clang-p2996/llvm/test/Transforms/EarlyCSE/flags.ll
Florian Hahn 361111906b [EarlyCSE] Retain poison flags, if program is UB if poison.
Poison-generating flags can be retained during CSE on the earlier
instruction , *if* the earlier instruction being poison causes UB. For
now, always take AND for floating point instructions.

https://alive2.llvm.org/ce/z/4K3D7P

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D115247
2021-12-11 15:11:44 +00:00

50 lines
1.7 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -early-cse -earlycse-debug-hash -S < %s | FileCheck %s
; RUN: opt -basic-aa -early-cse-memssa -S < %s | FileCheck %s
declare void @use(i1)
define void @test1(float %x, float %y) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: [[CMP1:%.*]] = fcmp oeq float [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: call void @use(i1 [[CMP1]])
; CHECK-NEXT: call void @use(i1 [[CMP1]])
; CHECK-NEXT: ret void
;
%cmp1 = fcmp nnan oeq float %y, %x
%cmp2 = fcmp oeq float %x, %y
call void @use(i1 %cmp1)
call void @use(i1 %cmp2)
ret void
}
declare void @use.i8(i8*)
define void @test_inbounds_program_ub_if_first_gep_poison(i8* %ptr, i64 %n) {
; CHECK-LABEL: @test_inbounds_program_ub_if_first_gep_poison(
; CHECK-NEXT: [[ADD_PTR_1:%.*]] = getelementptr inbounds i8, i8* [[PTR:%.*]], i64 [[N:%.*]]
; CHECK-NEXT: call void @use.i8(i8* noundef [[ADD_PTR_1]])
; CHECK-NEXT: call void @use.i8(i8* [[ADD_PTR_1]])
; CHECK-NEXT: ret void
;
%add.ptr.1 = getelementptr inbounds i8, i8* %ptr, i64 %n
call void @use.i8(i8* noundef %add.ptr.1)
%add.ptr.2 = getelementptr i8, i8* %ptr, i64 %n
call void @use.i8(i8* %add.ptr.2)
ret void
}
define void @test_inbounds_program_not_ub_if_first_gep_poison(i8* %ptr, i64 %n) {
; CHECK-LABEL: @test_inbounds_program_not_ub_if_first_gep_poison(
; CHECK-NEXT: [[ADD_PTR_1:%.*]] = getelementptr i8, i8* [[PTR:%.*]], i64 [[N:%.*]]
; CHECK-NEXT: call void @use.i8(i8* [[ADD_PTR_1]])
; CHECK-NEXT: call void @use.i8(i8* [[ADD_PTR_1]])
; CHECK-NEXT: ret void
;
%add.ptr.1 = getelementptr inbounds i8, i8* %ptr, i64 %n
call void @use.i8(i8* %add.ptr.1)
%add.ptr.2 = getelementptr i8, i8* %ptr, i64 %n
call void @use.i8(i8* %add.ptr.2)
ret void
}