From ffcae008d74c2008697211e66a72ff9a20696bc9 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Fri, 20 Dec 2019 00:04:31 +0300 Subject: [PATCH] [NFC][InstCombine] Add a test for assume-induced miscompile @escape() may throw here, we don't know that assumption, which is located afterwards in the same block, is executed, therefore %load arg of call to @escape() can not be marked as non-null. As noted in D71660 review by @nikic. --- llvm/test/Transforms/InstCombine/assume.ll | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/assume.ll b/llvm/test/Transforms/InstCombine/assume.ll index 0e9b78d..244413e 100644 --- a/llvm/test/Transforms/InstCombine/assume.ll +++ b/llvm/test/Transforms/InstCombine/assume.ll @@ -311,6 +311,23 @@ define i1 @nonnull4(i32** %a) { %rval = icmp eq i32* %load, null ret i1 %rval } +define i1 @nonnull5(i32** %a) { +; CHECK-LABEL: @nonnull5( +; CHECK-NEXT: [[LOAD:%.*]] = load i32*, i32** [[A:%.*]], align 8 +; CHECK-NEXT: tail call void @escape(i32* nonnull [[LOAD]]) +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32* [[LOAD]], null +; CHECK-NEXT: tail call void @llvm.assume(i1 [[CMP]]) +; CHECK-NEXT: ret i1 false +; + %load = load i32*, i32** %a + ;; This call may throw! + tail call void @escape(i32* %load) + %integral = ptrtoint i32* %load to i64 + %cmp = icmp slt i64 %integral, 0 + tail call void @llvm.assume(i1 %cmp) ; %load has at least highest bit set + %rval = icmp eq i32* %load, null + ret i1 %rval +} ; PR35846 - https://bugs.llvm.org/show_bug.cgi?id=35846 -- 2.7.4