[llvm] 869f60f - [PoisonChecking] Add tests with selects.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 18 10:51:45 PST 2022
Author: Florian Hahn
Date: 2022-12-18T18:51:15Z
New Revision: 869f60ffa13bdcb0221e65dfa04cfe9dcd132679
URL: https://github.com/llvm/llvm-project/commit/869f60ffa13bdcb0221e65dfa04cfe9dcd132679
DIFF: https://github.com/llvm/llvm-project/commit/869f60ffa13bdcb0221e65dfa04cfe9dcd132679.diff
LOG: [PoisonChecking] Add tests with selects.
This adds test coverage for a suggestion in D111643.
Added:
Modified:
llvm/test/Instrumentation/PoisonChecking/ub-checks.ll
Removed:
################################################################################
diff --git a/llvm/test/Instrumentation/PoisonChecking/ub-checks.ll b/llvm/test/Instrumentation/PoisonChecking/ub-checks.ll
index fae262c05a257..a5703ae02e17d 100644
--- a/llvm/test/Instrumentation/PoisonChecking/ub-checks.ll
+++ b/llvm/test/Instrumentation/PoisonChecking/ub-checks.ll
@@ -13,7 +13,7 @@ define void @store(ptr %base, i32 %a) {
; CHECK-NEXT: [[P:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i32 [[ADD]]
; CHECK-NEXT: [[TMP3:%.*]] = xor i1 [[TMP2]], true
; CHECK-NEXT: call void @__poison_checker_assert(i1 [[TMP3]])
-; CHECK-NEXT: store i8 0, ptr [[P]]
+; CHECK-NEXT: store i8 0, ptr [[P]], align 1
; CHECK-NEXT: ret void
;
%add = add nsw i32 %a, 1
@@ -30,7 +30,7 @@ define void @load(ptr %base, i32 %a) {
; CHECK-NEXT: [[P:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i32 [[ADD]]
; CHECK-NEXT: [[TMP3:%.*]] = xor i1 [[TMP2]], true
; CHECK-NEXT: call void @__poison_checker_assert(i1 [[TMP3]])
-; CHECK-NEXT: [[TMP4:%.*]] = load volatile i8, ptr [[P]]
+; CHECK-NEXT: [[TMP4:%.*]] = load volatile i8, ptr [[P]], align 1
; CHECK-NEXT: ret void
;
%add = add nsw i32 %a, 1
@@ -47,7 +47,7 @@ define void @atomicrmw(ptr %base, i32 %a) {
; CHECK-NEXT: [[P:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i32 [[ADD]]
; CHECK-NEXT: [[TMP3:%.*]] = xor i1 [[TMP2]], true
; CHECK-NEXT: call void @__poison_checker_assert(i1 [[TMP3]])
-; CHECK-NEXT: [[TMP4:%.*]] = atomicrmw add ptr [[P]], i8 1 seq_cst
+; CHECK-NEXT: [[TMP4:%.*]] = atomicrmw add ptr [[P]], i8 1 seq_cst, align 1
; CHECK-NEXT: ret void
;
%add = add nsw i32 %a, 1
@@ -64,7 +64,7 @@ define void @cmpxchg(ptr %base, i32 %a) {
; CHECK-NEXT: [[P:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i32 [[ADD]]
; CHECK-NEXT: [[TMP3:%.*]] = xor i1 [[TMP2]], true
; CHECK-NEXT: call void @__poison_checker_assert(i1 [[TMP3]])
-; CHECK-NEXT: [[TMP4:%.*]] = cmpxchg ptr [[P]], i8 1, i8 0 seq_cst seq_cst
+; CHECK-NEXT: [[TMP4:%.*]] = cmpxchg ptr [[P]], i8 1, i8 0 seq_cst seq_cst, align 1
; CHECK-NEXT: ret void
;
%add = add nsw i32 %a, 1
@@ -133,5 +133,58 @@ define i32 @srem(ptr %base, i32 %a) {
ret i32 %res
}
+define noundef i32 @select_cond_may_be_poison(i32 %a, i32 %b) {
+; CHECK-LABEL: @select_cond_may_be_poison(
+; CHECK-NEXT: [[TMP1:%.*]] = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 [[A:%.*]], i32 1)
+; CHECK-NEXT: [[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP1]], 1
+; CHECK-NEXT: [[ADD:%.*]] = add nuw i32 [[A]], 1
+; CHECK-NEXT: [[T:%.*]] = trunc i32 [[ADD]] to i1
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[T]], i32 [[ADD]], i32 [[B:%.*]]
+; CHECK-NEXT: ret i32 [[SEL]]
+;
+ %add = add nuw i32 %a, 1
+ %t = trunc i32 %add to i1
+ %sel = select i1 %t, i32 %add, i32 %b
+ ret i32 %sel
+}
+
+define noundef i32 @select_cond_true_third_op_may_be_poison(i32 %a, i32 %b) {
+; CHECK-LABEL: @select_cond_true_third_op_may_be_poison(
+; CHECK-NEXT: [[TMP1:%.*]] = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 [[A:%.*]], i32 1)
+; CHECK-NEXT: [[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP1]], 1
+; CHECK-NEXT: [[ADD:%.*]] = add nuw i32 [[A]], 1
+; CHECK-NEXT: [[SEL:%.*]] = select i1 true, i32 [[B:%.*]], i32 [[ADD]]
+; CHECK-NEXT: ret i32 [[SEL]]
+;
+ %add = add nuw i32 %a, 1
+ %sel = select i1 true, i32 %b, i32 %add
+ ret i32 %sel
+}
+
+define noundef i32 @select_cond_false_second_op_may_be_poison(i1 %c, i32 %a, i32 %b) {
+; CHECK-LABEL: @select_cond_false_second_op_may_be_poison(
+; CHECK-NEXT: [[TMP1:%.*]] = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 [[A:%.*]], i32 1)
+; CHECK-NEXT: [[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP1]], 1
+; CHECK-NEXT: [[ADD:%.*]] = add nuw i32 [[A]], 1
+; CHECK-NEXT: [[SEL:%.*]] = select i1 false, i32 [[ADD]], i32 [[B:%.*]]
+; CHECK-NEXT: ret i32 [[SEL]]
+;
+ %add = add nuw i32 %a, 1
+ %sel = select i1 false, i32 %add, i32 %b
+ ret i32 %sel
+}
+
+define noundef i32 @select_unknown_true_third_op_may_be_poison(i1 %c, i32 %a, i32 %b) {
+; CHECK-LABEL: @select_unknown_true_third_op_may_be_poison(
+; CHECK-NEXT: [[TMP1:%.*]] = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 [[A:%.*]], i32 1)
+; CHECK-NEXT: [[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP1]], 1
+; CHECK-NEXT: [[ADD:%.*]] = add nuw i32 [[A]], 1
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i32 [[B:%.*]], i32 [[ADD]]
+; CHECK-NEXT: ret i32 [[SEL]]
+;
+ %add = add nuw i32 %a, 1
+ %sel = select i1 %c, i32 %b, i32 %add
+ ret i32 %sel
+}
More information about the llvm-commits
mailing list