1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2 2; RUN: opt -S '-passes=separate-const-offset-from-gep<lower-gep>' < %s | FileCheck %s 3 4; These tests check that this pass does not incorrectly handle negative offsets. 5 6@c = internal constant [4 x i32] [i32 0, i32 1, i32 2, i32 3] 7 8; FIXME: We could optimize this case, but we don't currently. This test just 9; checks that we don't miscompile it. 10define i32 @sub_positive(i32 %a, i32 %b, ptr %ptr) { 11; CHECK-LABEL: define i32 @sub_positive 12; CHECK-SAME: (i32 [[A:%.*]], i32 [[B:%.*]], ptr [[PTR:%.*]]) { 13; CHECK-NEXT: entry: 14; CHECK-NEXT: [[TMP0:%.*]] = sub nuw nsw i32 15, [[A]] 15; CHECK-NEXT: [[TMP1:%.*]] = sub nuw nsw i32 [[B]], [[TMP0]] 16; CHECK-NEXT: [[TMP2:%.*]] = zext i32 [[TMP1]] to i64 17; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [4 x i32], ptr [[PTR]], i64 0, i64 [[TMP2]] 18; CHECK-NEXT: [[TMP4:%.*]] = load i32, ptr [[TMP3]], align 4 19; CHECK-NEXT: ret i32 [[TMP4]] 20; 21entry: 22 %0 = sub nuw nsw i32 15, %a 23 %1 = sub nuw nsw i32 %b, %0 24 %2 = zext i32 %1 to i64 25 %3 = getelementptr inbounds [4 x i32], ptr %ptr, i64 0, i64 %2 26 %4 = load i32, ptr %3 27 ret i32 %4 28} 29