| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| ; RUN: opt -passes=gvn -S %s | FileCheck %s |
| target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| declare noalias ptr @_Znam(i64) #1 |
| |
| ; Load of %i8 is an out of bounds load, which is folded to poison, which allows |
| ; us to elide the phi. |
| define i32 @TestNoAsan() { |
| ; CHECK-LABEL: @TestNoAsan( |
| ; CHECK-NEXT: bb: |
| ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @_Znam(i64 2) |
| ; CHECK-NEXT: [[I1:%.*]] = getelementptr inbounds i8, ptr [[I]], i64 1 |
| ; CHECK-NEXT: store i8 0, ptr [[I1]], align 1 |
| ; CHECK-NEXT: store i8 0, ptr [[I]], align 1 |
| ; CHECK-NEXT: [[I3:%.*]] = load i16, ptr [[I]], align 4 |
| ; CHECK-NEXT: [[I4:%.*]] = icmp eq i16 [[I3]], 0 |
| ; CHECK-NEXT: br i1 [[I4]], label [[BB10:%.*]], label [[BB5:%.*]] |
| ; CHECK: bb5: |
| ; CHECK-NEXT: [[I6:%.*]] = getelementptr inbounds i8, ptr [[I]], i64 2 |
| ; CHECK-NEXT: br label [[BB10]] |
| ; CHECK: bb10: |
| ; CHECK-NEXT: ret i32 0 |
| ; |
| bb: |
| %i = tail call noalias ptr @_Znam(i64 2) |
| %i1 = getelementptr inbounds i8, ptr %i, i64 1 |
| store i8 0, ptr %i1, align 1 |
| store i8 0, ptr %i, align 1 |
| %i3 = load i16, ptr %i, align 4 |
| %i4 = icmp eq i16 %i3, 0 |
| br i1 %i4, label %bb10, label %bb5 |
| |
| bb5: ; preds = %bb |
| %i6 = getelementptr inbounds i8, ptr %i, i64 2 |
| %i8 = load i16, ptr %i6, align 2 |
| %i9 = sext i16 %i8 to i32 |
| br label %bb10 |
| |
| bb10: ; preds = %bb5, %bb |
| %i11 = phi i32 [ %i9, %bb5 ], [ 0, %bb ] |
| ret i32 %i11 |
| } |
| |
| define i32 @TestAsan() sanitize_address { |
| ; CHECK-LABEL: @TestAsan( |
| ; CHECK-NEXT: bb: |
| ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @_Znam(i64 2) |
| ; CHECK-NEXT: [[I1:%.*]] = getelementptr inbounds i8, ptr [[I]], i64 1 |
| ; CHECK-NEXT: store i8 0, ptr [[I1]], align 1 |
| ; CHECK-NEXT: store i8 0, ptr [[I]], align 1 |
| ; CHECK-NEXT: [[I3:%.*]] = load i16, ptr [[I]], align 4 |
| ; CHECK-NEXT: [[I4:%.*]] = icmp eq i16 [[I3]], 0 |
| ; CHECK-NEXT: br i1 [[I4]], label [[BB10:%.*]], label [[BB5:%.*]] |
| ; CHECK: bb5: |
| ; CHECK-NEXT: [[I6:%.*]] = getelementptr inbounds i8, ptr [[I]], i64 2 |
| ; CHECK-NEXT: [[I8:%.*]] = load i16, ptr [[I6]], align 2 |
| ; CHECK-NEXT: [[I9:%.*]] = sext i16 [[I8]] to i32 |
| ; CHECK-NEXT: br label [[BB10]] |
| ; CHECK: bb10: |
| ; CHECK-NEXT: [[I11:%.*]] = phi i32 [ [[I9]], [[BB5]] ], [ 0, [[BB:%.*]] ] |
| ; CHECK-NEXT: ret i32 [[I11]] |
| ; |
| bb: |
| %i = tail call noalias ptr @_Znam(i64 2) |
| %i1 = getelementptr inbounds i8, ptr %i, i64 1 |
| store i8 0, ptr %i1, align 1 |
| store i8 0, ptr %i, align 1 |
| %i3 = load i16, ptr %i, align 4 |
| %i4 = icmp eq i16 %i3, 0 |
| br i1 %i4, label %bb10, label %bb5 |
| |
| bb5: ; preds = %bb |
| %i6 = getelementptr inbounds i8, ptr %i, i64 2 |
| %i8 = load i16, ptr %i6, align 2 |
| %i9 = sext i16 %i8 to i32 |
| br label %bb10 |
| |
| bb10: ; preds = %bb5, %bb |
| %i11 = phi i32 [ %i9, %bb5 ], [ 0, %bb ] |
| ret i32 %i11 |
| } |
| |
| define i32 @TestHWAsan() sanitize_hwaddress { |
| ; CHECK-LABEL: @TestHWAsan( |
| ; CHECK-NEXT: bb: |
| ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @_Znam(i64 2) |
| ; CHECK-NEXT: [[I1:%.*]] = getelementptr inbounds i8, ptr [[I]], i64 1 |
| ; CHECK-NEXT: store i8 0, ptr [[I1]], align 1 |
| ; CHECK-NEXT: store i8 0, ptr [[I]], align 1 |
| ; CHECK-NEXT: [[I3:%.*]] = load i16, ptr [[I]], align 4 |
| ; CHECK-NEXT: [[I4:%.*]] = icmp eq i16 [[I3]], 0 |
| ; CHECK-NEXT: br i1 [[I4]], label [[BB10:%.*]], label [[BB5:%.*]] |
| ; CHECK: bb5: |
| ; CHECK-NEXT: [[I6:%.*]] = getelementptr inbounds i8, ptr [[I]], i64 2 |
| ; CHECK-NEXT: [[I8:%.*]] = load i16, ptr [[I6]], align 2 |
| ; CHECK-NEXT: [[I9:%.*]] = sext i16 [[I8]] to i32 |
| ; CHECK-NEXT: br label [[BB10]] |
| ; CHECK: bb10: |
| ; CHECK-NEXT: [[I11:%.*]] = phi i32 [ [[I9]], [[BB5]] ], [ 0, [[BB:%.*]] ] |
| ; CHECK-NEXT: ret i32 [[I11]] |
| ; |
| bb: |
| %i = tail call noalias ptr @_Znam(i64 2) |
| %i1 = getelementptr inbounds i8, ptr %i, i64 1 |
| store i8 0, ptr %i1, align 1 |
| store i8 0, ptr %i, align 1 |
| %i3 = load i16, ptr %i, align 4 |
| %i4 = icmp eq i16 %i3, 0 |
| br i1 %i4, label %bb10, label %bb5 |
| |
| bb5: ; preds = %bb |
| %i6 = getelementptr inbounds i8, ptr %i, i64 2 |
| %i8 = load i16, ptr %i6, align 2 |
| %i9 = sext i16 %i8 to i32 |
| br label %bb10 |
| |
| bb10: ; preds = %bb5, %bb |
| %i11 = phi i32 [ %i9, %bb5 ], [ 0, %bb ] |
| ret i32 %i11 |
| } |