[llvm] ffcae00 - [NFC][InstCombine] Add a test for assume-induced miscompile

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 19 14:51:32 PST 2019


Author: Roman Lebedev
Date: 2019-12-20T01:47:56+03:00
New Revision: ffcae008d74c2008697211e66a72ff9a20696bc9

URL: https://github.com/llvm/llvm-project/commit/ffcae008d74c2008697211e66a72ff9a20696bc9
DIFF: https://github.com/llvm/llvm-project/commit/ffcae008d74c2008697211e66a72ff9a20696bc9.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/assume.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/assume.ll b/llvm/test/Transforms/InstCombine/assume.ll
index 0e9b78d2e4ec..244413eb56b0 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
 


        


More information about the llvm-commits mailing list