Files
clang-p2996/llvm/test/Transforms/GVN/noundef.ll
luxufan 232698dc17 [Local][InstCombine][GVN] Handle !noundef metadata in combineMetadata
Handle !noundef metadata in comhineMetadata. The behavior of violating
!noundef metadata is undefined behavior. So if K dominates J, we can
preserve it uncontionally, otherwise, we preserve it if both K and J
have !noundef metadata been set.

This patch also makes !noundef metadata added in KnownIDs when doing
instruction combine for phi node or global value numbering for loads.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D142801
2023-02-02 14:25:13 +08:00

29 lines
826 B
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes=gvn -S %s | FileCheck %s
;
;Check that !noundef metadata is combined.
define i32 @one_noundef(ptr %p) {
; CHECK-LABEL: @one_noundef(
; CHECK-NEXT: [[A:%.*]] = load i32, ptr [[P:%.*]], align 4, !noundef !0
; CHECK-NEXT: [[C:%.*]] = add i32 [[A]], [[A]]
; CHECK-NEXT: ret i32 [[C]]
;
%a = load i32, ptr %p, !noundef !0
%b = load i32, ptr %p
%c = add i32 %a, %b
ret i32 %c
}
define i32 @both_noundef(ptr %p) {
; CHECK-LABEL: @both_noundef(
; CHECK-NEXT: [[A:%.*]] = load i32, ptr [[P:%.*]], align 4, !noundef !0
; CHECK-NEXT: [[C:%.*]] = add i32 [[A]], [[A]]
; CHECK-NEXT: ret i32 [[C]]
;
%a = load i32, ptr %p, !noundef !0
%b = load i32, ptr %p, !noundef !0
%c = add i32 %a, %b
ret i32 %c
}
!0 = !{}