[InstCombine] Remove unnecessary UB from some tests.
authorFlorian Hahn <flo@fhahn.com>
Sat, 11 Jun 2022 22:22:48 +0000 (23:22 +0100)
committerFlorian Hahn <flo@fhahn.com>
Sat, 11 Jun 2022 22:22:49 +0000 (23:22 +0100)
13 files changed:
llvm/test/Transforms/InstCombine/2004-12-08-RemInfiniteLoop.ll
llvm/test/Transforms/InstCombine/2006-12-23-Select-Cmp-Cmp.ll
llvm/test/Transforms/InstCombine/2009-02-25-CrashZeroSizeArray.ll
llvm/test/Transforms/InstCombine/2010-05-30-memcpy-Struct.ll
llvm/test/Transforms/InstCombine/X86/shufflemask-undef-inseltpoison.ll
llvm/test/Transforms/InstCombine/X86/shufflemask-undef.ll
llvm/test/Transforms/InstCombine/alloca-big.ll
llvm/test/Transforms/InstCombine/call-intrinsics.ll
llvm/test/Transforms/InstCombine/pr35515.ll
llvm/test/Transforms/InstCombine/pr38677.ll
llvm/test/Transforms/InstCombine/pr38984-inseltpoison.ll
llvm/test/Transforms/InstCombine/pr38984.ll
llvm/test/Transforms/InstCombine/stack-overalign.ll

index 92162eb..9db05cd 100644 (file)
@@ -1,6 +1,6 @@
 ; RUN: opt < %s -passes=instcombine
 
-define i32 @test(i32 %X) {
+define i32 @test(i32 %X, i32 %Z) {
         %Y = srem i32 %X, undef         ; <i32> [#uses=1]
         ret i32 %Y
 }
index 4d1b5e7..80e43cb 100644 (file)
@@ -12,11 +12,11 @@ target triple = "i686-pc-linux-gnu"
        %struct.mng_savedata = type { i8, i8, i8, i8, i8, i8, i8, i16, i16, i16, i8, i16, i8, i8, i32, i32, i8, i32, i32, i32, i32, i32, [256 x %struct.mng_palette8e], i32, [256 x i8], i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i8*, i16, i16, i16 }
        %struct.z_stream = type { i8*, i32, i32, i8*, i32, i32, i8*, %struct.internal_state*, i8* (i8*, i32, i32)*, void (i8*, i8*)*, i8*, i32, i32, i32 }
 
-define void @mng_write_basi() {
+define void @mng_write_basi(i8* %src1, i16* %src2) {
 entry:
-       %tmp = load i8, i8* null                ; <i8> [#uses=1]
+       %tmp = load i8, i8* %src1 ; <i8> [#uses=1]
        %tmp.upgrd.1 = icmp ugt i8 %tmp, 8              ; <i1> [#uses=1]
-       %tmp.upgrd.2 = load i16, i16* null              ; <i16> [#uses=2]
+       %tmp.upgrd.2 = load i16, i16* %src2; <i16> [#uses=2]
        %tmp3 = icmp eq i16 %tmp.upgrd.2, 255           ; <i1> [#uses=1]
        %tmp7 = icmp eq i16 %tmp.upgrd.2, -1            ; <i1> [#uses=1]
        %bOpaque.0.in = select i1 %tmp.upgrd.1, i1 %tmp7, i1 %tmp3              ; <i1> [#uses=1]
index 78b8344..c261676 100644 (file)
@@ -3,13 +3,13 @@
 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
 target triple = "i386-pc-linux-gnu"
 
-define void @_ada_c32001b(i32 %tmp5) {
+define void @_ada_c32001b(i32 %tmp5, i32* %src) {
 entry:
        %max289 = select i1 false, i32 %tmp5, i32 0             ; <i32> [#uses=1]
        %tmp6 = mul i32 %max289, 4              ; <i32> [#uses=1]
        %tmp7 = alloca i8, i32 0                ; <i8*> [#uses=1]
        %tmp8 = bitcast i8* %tmp7 to [0 x [0 x i32]]*           ; <[0 x [0 x i32]]*> [#uses=1]
-       %tmp11 = load i32, i32* null, align 1           ; <i32> [#uses=1]
+       %tmp11 = load i32, i32* %src, align 1           ; <i32> [#uses=1]
        %tmp12 = icmp eq i32 %tmp11, 3          ; <i1> [#uses=1]
        %tmp13 = zext i1 %tmp12 to i8           ; <i8> [#uses=1]
        %tmp14 = ashr i32 %tmp6, 2              ; <i32> [#uses=1]
index 8e93097..a1c71f0 100644 (file)
@@ -9,15 +9,15 @@ target triple = "x86_64-unknown-linux-gnu"
 
 @.str = private constant [3 x i8] c"%s\00"
 
-define void @CopyEventArg(%union.anon* %ev) nounwind {
+define void @CopyEventArg(%union.anon* %ev, i8* %src) nounwind {
 ; CHECK-LABEL: @CopyEventArg(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[CSTR:%.*]] = bitcast %union.anon* [[EV:%.*]] to i8*
-; CHECK-NEXT:    [[STRCPY:%.*]] = call i8* @strcpy(i8* noundef nonnull dereferenceable(1) undef, i8* noundef nonnull dereferenceable(1) [[CSTR]])
+; CHECK-NEXT:    [[STRCPY:%.*]] = call i8* @strcpy(i8* noundef nonnull dereferenceable(1) [[SRC:%.*]], i8* noundef nonnull dereferenceable(1) [[CSTR]])
 ; CHECK-NEXT:    ret void
 ;
 entry:
-  %call = call i32 (i8*, i8*, ...) @sprintf(i8* undef, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %union.anon* %ev) nounwind
+  %call = call i32 (i8*, i8*, ...) @sprintf(i8* %src, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %union.anon* %ev) nounwind
   ret void
 }
 
index d2fab4c..0fbfee1 100644 (file)
@@ -68,9 +68,9 @@ target triple = "i386-apple-darwin9"
        %struct.PPStreamToken = type { { i16, i16, i32 } }
        %struct._VMConstants = type { <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, float, float, float, float, float, float, float, float, float, float, float, float, [256 x float], [528 x i8], { void (i8*, i8*, i32, i8*)*, float (float)*, float (float)*, float (float)*, i32 (float)* } }
 
-define i32 @foo(%struct.State* %dst, <4 x float>* %prgrm, <4 x float>** %buffs, %struct._VMConstants* %cnstn, %struct.PPStreamToken* %pstrm, %struct.PluginBufferData* %gpctx, %struct.VMTextures* %txtrs, %struct.VMGPStack* %gpstk) nounwind {
+define i32 @foo(%struct.State* %dst, <4 x float>* %prgrm, <4 x float>** %buffs, %struct._VMConstants* %cnstn, %struct.PPStreamToken* %pstrm, %struct.PluginBufferData* %gpctx, %struct.VMTextures* %txtrs, %struct.VMGPStack* %gpstk, <4 x float>* %src) nounwind {
 bb266.i:
-       getelementptr <4 x float>, <4 x float>* null, i32 11            ; <<4 x float>*>:0 [#uses=1]
+       getelementptr <4 x float>, <4 x float>* %src, i32 11            ; <<4 x float>*>:0 [#uses=1]
        load <4 x float>, <4 x float>* %0, align 16             ; <<4 x float>>:1 [#uses=1]
        shufflevector <4 x float> %1, <4 x float> poison, <4 x i32> < i32 0, i32 1, i32 1, i32 1 >              ; <<4 x float>>:2 [#uses=1]
        shufflevector <4 x float> %2, <4 x float> poison, <4 x i32> < i32 0, i32 4, i32 1, i32 5 >              ; <<4 x float>>:3 [#uses=1]
@@ -95,10 +95,10 @@ bb266.i:
        br i1 %16, label %bb5574.i, label %bb4521.i
 
 bb4521.i:              ; preds = %bb266.i
-       unreachable
+  ret i32 0
 
 bb5574.i:              ; preds = %bb266.i
-       unreachable
+  ret i32 1
 }
 
 declare <4 x float> @llvm.x86.sse.cmp.ps(<4 x float>, <4 x float>, i8) nounwind readnone
index 4ce7a28..09f102c 100644 (file)
@@ -68,9 +68,9 @@ target triple = "i386-apple-darwin9"
        %struct.PPStreamToken = type { { i16, i16, i32 } }
        %struct._VMConstants = type { <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, float, float, float, float, float, float, float, float, float, float, float, float, [256 x float], [528 x i8], { void (i8*, i8*, i32, i8*)*, float (float)*, float (float)*, float (float)*, i32 (float)* } }
 
-define i32 @foo(%struct.State* %dst, <4 x float>* %prgrm, <4 x float>** %buffs, %struct._VMConstants* %cnstn, %struct.PPStreamToken* %pstrm, %struct.PluginBufferData* %gpctx, %struct.VMTextures* %txtrs, %struct.VMGPStack* %gpstk) nounwind {
+define i32 @foo(%struct.State* %dst, <4 x float>* %prgrm, <4 x float>** %buffs, %struct._VMConstants* %cnstn, %struct.PPStreamToken* %pstrm, %struct.PluginBufferData* %gpctx, %struct.VMTextures* %txtrs, %struct.VMGPStack* %gpstk, <4 x float>* %src) nounwind {
 bb266.i:
-       getelementptr <4 x float>, <4 x float>* null, i32 11            ; <<4 x float>*>:0 [#uses=1]
+       getelementptr <4 x float>, <4 x float>* %src, i32 11            ; <<4 x float>*>:0 [#uses=1]
        load <4 x float>, <4 x float>* %0, align 16             ; <<4 x float>>:1 [#uses=1]
        shufflevector <4 x float> %1, <4 x float> undef, <4 x i32> < i32 0, i32 1, i32 1, i32 1 >               ; <<4 x float>>:2 [#uses=1]
        shufflevector <4 x float> %2, <4 x float> undef, <4 x i32> < i32 0, i32 4, i32 1, i32 5 >               ; <<4 x float>>:3 [#uses=1]
@@ -95,10 +95,10 @@ bb266.i:
        br i1 %16, label %bb5574.i, label %bb4521.i
 
 bb4521.i:              ; preds = %bb266.i
-       unreachable
+       ret i32 0
 
 bb5574.i:              ; preds = %bb266.i
-       unreachable
+  ret i32 1
 }
 
 declare <4 x float> @llvm.x86.sse.cmp.ps(<4 x float>, <4 x float>, i8) nounwind readnone
index 3891b19..27e76e7 100644 (file)
@@ -2,15 +2,15 @@
 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
 
 ; OSS-Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=5223
-define void @test_bigalloc() {
+define void @test_bigalloc(i8** %dst) {
 ; CHECK-LABEL: @test_bigalloc(
 ; CHECK-NEXT:    [[TMP1:%.*]] = alloca [18446744069414584320 x i8], align 1
 ; CHECK-NEXT:    [[DOTSUB:%.*]] = getelementptr inbounds [18446744069414584320 x i8], [18446744069414584320 x i8]* [[TMP1]], i64 0, i64 0
-; CHECK-NEXT:    store i8* [[DOTSUB]], i8** undef, align 8
+; CHECK-NEXT:    store i8* [[DOTSUB]], i8** [[DST:%.*]], align 8
 ; CHECK-NEXT:    ret void
 ;
   %1 = alloca i8, i864 -4294967296
-  %2 = getelementptr i8, i8* %1, i1 undef
-  store i8* %2, i8** undef
+  %2 = getelementptr i8, i8* %1, i1 0
+  store i8* %2, i8** %dst
   ret void
 }
index dc2394c..0efc4b8 100644 (file)
@@ -1,7 +1,7 @@
 ; RUN: opt < %s -passes=instcombine | llvm-dis
 
-@X = global i8 0                ; <i8*> [#uses=3]
-@Y = global i8 12               ; <i8*> [#uses=2]
+@X = global i8 0
+@Y = global i8 12
 
 declare void @llvm.memmove.p0i8.p0i8.i32(i8*, i8*, i32, i1)
 
@@ -10,10 +10,10 @@ declare void @llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i1)
 declare void @llvm.memset.p0i8.i32(i8*, i8, i32, i1)
 
 define void @zero_byte_test() {
-        ; These process zero bytes, so they are a noop.
-        call void @llvm.memmove.p0i8.p0i8.i32(i8* align 128 @X, i8* align 128 @Y, i32 0, i1 false )
-        call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 128 @X, i8* align 128 @Y, i32 0, i1 false )
-        call void @llvm.memset.p0i8.i32(i8* align 128 @X, i8 123, i32 0, i1 false )
-        ret void
+  ; These process zero bytes, so they are a noop.
+  call void @llvm.memmove.p0i8.p0i8.i32(i8* @X, i8* @Y, i32 0, i1 false )
+  call void @llvm.memcpy.p0i8.p0i8.i32(i8* @X, i8* @Y, i32 0, i1 false )
+  call void @llvm.memset.p0i8.i32(i8* @X, i8 123, i32 0, i1 false )
+  ret void
 }
 
index c862bee..4604c13 100644 (file)
@@ -5,7 +5,7 @@
 @g_49 = external local_unnamed_addr global { i8, i8, i8, i8, i8 }, align 2
 
 ; CHECK-LABEL: @func_24(
-define fastcc void @func_24() {
+define i40 @func_24() {
 entry:
   %bf.load81 = load i40, i40* bitcast ({ i8, i8, i8, i8, i8 }* @g_49 to i40*), align 2
   %bf.clear = and i40 %bf.load81, -274869518337
@@ -16,5 +16,5 @@ entry:
   %tmp3 = shl nuw nsw i32 %tmp2, 23
   %bf.shl154 = zext i32 %tmp3 to i40
   %bf.set156 = or i40 %bf.clear, %bf.shl154
-  unreachable
+  ret i40 %bf.set156
 }
index df36e79..63c0cab 100644 (file)
@@ -4,17 +4,17 @@
 @A = extern_weak global i32, align 4
 @B = extern_weak global i32, align 4
 
-define i32 @foo(i1 %which) {
+define i32 @foo(i1 %which, ptr %dst) {
 ; CHECK-LABEL: @foo(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    br i1 true, label [[FINAL:%.*]], label [[DELAY:%.*]]
 ; CHECK:       delay:
 ; CHECK-NEXT:    br label [[FINAL]]
 ; CHECK:       final:
-; CHECK-NEXT:    [[USE2:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ select (i1 icmp eq (i32* @A, i32* @B), i32 2, i32 1), [[DELAY]] ]
+; CHECK-NEXT:    [[USE2:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ select (i1 icmp eq (ptr @A, ptr @B), i32 2, i32 1), [[DELAY]] ]
 ; CHECK-NEXT:    [[B7:%.*]] = mul i32 [[USE2]], 2147483647
 ; CHECK-NEXT:    [[C3:%.*]] = icmp eq i32 [[B7]], 0
-; CHECK-NEXT:    store i1 [[C3]], i1* undef, align 1
+; CHECK-NEXT:    store i1 [[C3]], ptr [[DST:%.*]], align 1
 ; CHECK-NEXT:    ret i32 [[USE2]]
 ;
 entry:
@@ -24,10 +24,10 @@ delay:                                            ; preds = %entry
   br label %final
 
 final:                                            ; preds = %delay, %entry
-  %use2 = phi i1 [ false, %entry ], [ icmp eq (i32* @A, i32* @B), %delay ]
+  %use2 = phi i1 [ false, %entry ], [ icmp eq (ptr @A, ptr @B), %delay ]
   %value = select i1 %use2, i32 2, i32 1
   %B7 = mul i32 %value, 2147483647
   %C3 = icmp ule i32 %B7, 0
-  store i1 %C3, i1* undef
+  store i1 %C3, ptr %dst
   ret i32 %value
 }
index d576ea2..0f9886c 100644 (file)
@@ -12,7 +12,7 @@ define <4 x i1> @PR38984_1() {
 ; CHECK-NEXT:    ret <4 x i1> <i1 true, i1 true, i1 true, i1 true>
 ;
 entry:
-  %0 = load i16, i16* getelementptr ([4 x i16], [4 x i16]* @offsets, i16 0, i16 undef), align 1
+  %0 = load i16, i16* getelementptr ([4 x i16], [4 x i16]* @offsets, i16 0, i16 0), align 1
   %1 = insertelement <4 x i16> poison, i16 %0, i32 3
   %2 = getelementptr i32, i32* null, <4 x i16> %1
   %3 = getelementptr i32, i32* null, <4 x i16> %1
@@ -24,7 +24,7 @@ entry:
 define <4 x i1> @PR38984_2() {
 ; CHECK-LABEL: @PR38984_2(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:    [[TMP0:%.*]] = load i16, i16* getelementptr ([4 x i16], [4 x i16]* @offsets, i16 0, i16 undef), align 2
+; CHECK-NEXT:    [[TMP0:%.*]] = load i16, i16* getelementptr inbounds ([4 x i16], [4 x i16]* @offsets, i16 0, i16 0), align 2
 ; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <4 x i16> poison, i16 [[TMP0]], i64 3
 ; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr i16, i16* getelementptr inbounds ([21 x i16], [21 x i16]* @a, i16 1, i16 0), <4 x i16> [[TMP1]]
 ; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr i16, i16* null, <4 x i16> [[TMP1]]
@@ -32,7 +32,7 @@ define <4 x i1> @PR38984_2() {
 ; CHECK-NEXT:    ret <4 x i1> [[TMP4]]
 ;
 entry:
-  %0 = load i16, i16* getelementptr ([4 x i16], [4 x i16]* @offsets, i16 0, i16 undef)
+  %0 = load i16, i16* getelementptr ([4 x i16], [4 x i16]* @offsets, i16 0, i16 0)
   %1 = insertelement <4 x i16> poison, i16 %0, i32 3
   %2 = getelementptr i16, i16* getelementptr ([21 x i16], [21 x i16]* @a, i64 1, i32 0), <4 x i16> %1
   %3 = getelementptr i16, i16* null, <4 x i16> %1
index c7ee472..97b03ea 100644 (file)
@@ -12,7 +12,7 @@ define <4 x i1> @PR38984_1() {
 ; CHECK-NEXT:    ret <4 x i1> <i1 true, i1 true, i1 true, i1 true>
 ;
 entry:
-  %0 = load i16, i16* getelementptr ([4 x i16], [4 x i16]* @offsets, i16 0, i16 undef), align 1
+  %0 = load i16, i16* getelementptr ([4 x i16], [4 x i16]* @offsets, i16 0, i16 0), align 1
   %1 = insertelement <4 x i16> undef, i16 %0, i32 3
   %2 = getelementptr i32, i32* null, <4 x i16> %1
   %3 = getelementptr i32, i32* null, <4 x i16> %1
@@ -24,7 +24,7 @@ entry:
 define <4 x i1> @PR38984_2() {
 ; CHECK-LABEL: @PR38984_2(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:    [[TMP0:%.*]] = load i16, i16* getelementptr ([4 x i16], [4 x i16]* @offsets, i16 0, i16 undef), align 2
+; CHECK-NEXT:    [[TMP0:%.*]] = load i16, i16* getelementptr inbounds ([4 x i16], [4 x i16]* @offsets, i16 0, i16 0), align 2
 ; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <4 x i16> undef, i16 [[TMP0]], i64 3
 ; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr i16, i16* getelementptr inbounds ([21 x i16], [21 x i16]* @a, i16 1, i16 0), <4 x i16> [[TMP1]]
 ; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr i16, i16* null, <4 x i16> [[TMP1]]
@@ -32,7 +32,7 @@ define <4 x i1> @PR38984_2() {
 ; CHECK-NEXT:    ret <4 x i1> [[TMP4]]
 ;
 entry:
-  %0 = load i16, i16* getelementptr ([4 x i16], [4 x i16]* @offsets, i16 0, i16 undef)
+  %0 = load i16, i16* getelementptr ([4 x i16], [4 x i16]* @offsets, i16 0, i16 0)
   %1 = insertelement <4 x i16> undef, i16 %0, i32 3
   %2 = getelementptr i16, i16* getelementptr ([21 x i16], [21 x i16]* @a, i64 1, i32 0), <4 x i16> %1
   %3 = getelementptr i16, i16* null, <4 x i16> %1
index f1ebcbf..2abcca4 100644 (file)
@@ -19,7 +19,7 @@
 
 define void @foo() nounwind {
 entry:
-  %src = alloca [1024 x i8], align 1
+  %src = alloca [1024 x i8], align 64
   %src1 = getelementptr [1024 x i8], [1024 x i8]* %src, i32 0, i32 0
   call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 32 getelementptr inbounds ([1024 x i8], [1024 x i8]* @dst, i32 0, i32 0), i8* align 32 %src1, i32 1024, i1 false)
   call void @frob(i8* %src1) nounwind