[llvm] r365523 - [InstCombine] add tests for trunc(load); NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 9 11:06:16 PDT 2019


Author: spatel
Date: Tue Jul  9 11:06:16 2019
New Revision: 365523

URL: http://llvm.org/viewvc/llvm-project?rev=365523&view=rev
Log:
[InstCombine] add tests for trunc(load); NFC

I'm not sure if transforming any of these is valid as
a target-independent fold, but we might as well have
a few tests here to confirm or deny our position.

Added:
    llvm/trunk/test/Transforms/InstCombine/trunc-load.ll

Added: llvm/trunk/test/Transforms/InstCombine/trunc-load.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/trunc-load.ll?rev=365523&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/trunc-load.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/trunc-load.ll Tue Jul  9 11:06:16 2019
@@ -0,0 +1,73 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instcombine -S -data-layout="e-n16:32:64" | FileCheck %s --check-prefixes=CHECK,LE
+; RUN: opt < %s -instcombine -S -data-layout="E-n16:32:64" | FileCheck %s --check-prefixes=CHECK,BE
+
+define i32 @truncload(i64* %ptr) {
+; CHECK-LABEL: @truncload(
+; CHECK-NEXT:    [[X:%.*]] = load i64, i64* [[PTR:%.*]], align 4
+; CHECK-NEXT:    [[R:%.*]] = trunc i64 [[X]] to i32
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %x = load i64, i64* %ptr
+  %r = trunc i64 %x to i32
+  ret i32 %r
+}
+
+define i16 @truncload_align(i32* %ptr) {
+; CHECK-LABEL: @truncload_align(
+; CHECK-NEXT:    [[X:%.*]] = load i32, i32* [[PTR:%.*]], align 16
+; CHECK-NEXT:    [[R:%.*]] = trunc i32 [[X]] to i16
+; CHECK-NEXT:    ret i16 [[R]]
+;
+  %x = load i32, i32* %ptr, align 16
+  %r = trunc i32 %x to i16
+  ret i16 %r
+}
+
+declare void @use(i64)
+
+define i32 @truncload_extra_use(i64* %ptr) {
+; CHECK-LABEL: @truncload_extra_use(
+; CHECK-NEXT:    [[X:%.*]] = load i64, i64* [[PTR:%.*]], align 2
+; CHECK-NEXT:    call void @use(i64 [[X]])
+; CHECK-NEXT:    [[R:%.*]] = trunc i64 [[X]] to i32
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %x = load i64, i64* %ptr, align 2
+  call void @use(i64 %x)
+  %r = trunc i64 %x to i32
+  ret i32 %r
+}
+
+define i8 @truncload_type(i64* %ptr) {
+; CHECK-LABEL: @truncload_type(
+; CHECK-NEXT:    [[X:%.*]] = load i64, i64* [[PTR:%.*]], align 2
+; CHECK-NEXT:    [[R:%.*]] = trunc i64 [[X]] to i8
+; CHECK-NEXT:    ret i8 [[R]]
+;
+  %x = load i64, i64* %ptr, align 2
+  %r = trunc i64 %x to i8
+  ret i8 %r
+}
+
+define i32 @truncload_volatile(i64* %ptr) {
+; CHECK-LABEL: @truncload_volatile(
+; CHECK-NEXT:    [[X:%.*]] = load volatile i64, i64* [[PTR:%.*]], align 8
+; CHECK-NEXT:    [[R:%.*]] = trunc i64 [[X]] to i32
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %x = load volatile i64, i64* %ptr, align 8
+  %r = trunc i64 %x to i32
+  ret i32 %r
+}
+
+define i32 @truncload_address_space(i64 addrspace(1)* %ptr) {
+; CHECK-LABEL: @truncload_address_space(
+; CHECK-NEXT:    [[X:%.*]] = load i64, i64 addrspace(1)* [[PTR:%.*]], align 4
+; CHECK-NEXT:    [[R:%.*]] = trunc i64 [[X]] to i32
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %x = load i64, i64 addrspace(1)* %ptr, align 4
+  %r = trunc i64 %x to i32
+  ret i32 %r
+}




More information about the llvm-commits mailing list