| // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 6 | |
| // RUN: %clang -S -emit-llvm -O2 --target=x86_64-windows-msvc -fdefined-pointer-subtraction -fno-discard-value-names -fms-extensions %s -o - | FileCheck %s --check-prefix=DPS | |
| // RUN: %clang -S -emit-llvm -O2 --target=x86_64-windows-msvc -fwrapv-pointer -fno-discard-value-names -fms-extensions %s -o - | FileCheck %s --check-prefix=WRAPV | |
| // Check that pointer subtraction isn't nuw/nsv and sdiv isn't exact | |
| // DPS-LABEL: define dso_local noundef range(i64 -2305843009213693952, 2305843009213693952) i64 @sub( | |
| // DPS-SAME: ptr nofree noundef readnone captures(address) [[P:%.*]], ptr nofree noundef readnone captures(address) [[Q:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { | |
| // DPS-NEXT: [[ENTRY:.*:]] | |
| // DPS-NEXT: [[SUB_PTR_LHS_CAST:%.*]] = ptrtoaddr ptr [[P]] to i64 | |
| // DPS-NEXT: [[SUB_PTR_RHS_CAST:%.*]] = ptrtoaddr ptr [[Q]] to i64 | |
| // DPS-NEXT: [[SUB_PTR_SUB:%.*]] = sub i64 [[SUB_PTR_LHS_CAST]], [[SUB_PTR_RHS_CAST]] | |
| // DPS-NEXT: [[SUB_PTR_DIV:%.*]] = sdiv i64 [[SUB_PTR_SUB]], 4 | |
| // DPS-NEXT: ret i64 [[SUB_PTR_DIV]] | |
| // | |
| // WRAPV-LABEL: define dso_local range(i64 -2305843009213693952, 2305843009213693952) i64 @sub( | |
| // WRAPV-SAME: ptr noundef [[P:%.*]], ptr noundef [[Q:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { | |
| // WRAPV-NEXT: [[ENTRY:.*:]] | |
| // WRAPV-NEXT: [[SUB_PTR_LHS_CAST:%.*]] = ptrtoint ptr [[P]] to i64 | |
| // WRAPV-NEXT: [[SUB_PTR_RHS_CAST:%.*]] = ptrtoint ptr [[Q]] to i64 | |
| // WRAPV-NEXT: [[SUB_PTR_SUB:%.*]] = sub i64 [[SUB_PTR_LHS_CAST]], [[SUB_PTR_RHS_CAST]] | |
| // WRAPV-NEXT: [[SUB_PTR_DIV:%.*]] = ashr exact i64 [[SUB_PTR_SUB]], 2 | |
| // WRAPV-NEXT: ret i64 [[SUB_PTR_DIV]] | |
| // | |
| __declspec(noinline) long long sub(long* p, long* q) { | |
| return p - q; | |
| } | |