[llvm] 2554a85 - [CodeGenPrepare][test] Add test for sinking of truncs demonstrating nsw/nuw are dropped

Alex Bradbury via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 25 07:03:15 PDT 2024


Author: Alex Bradbury
Date: 2024-04-25T15:01:55+01:00
New Revision: 2554a85c0375b4c1c7c4f461811babef67e1a403

URL: https://github.com/llvm/llvm-project/commit/2554a85c0375b4c1c7c4f461811babef67e1a403
DIFF: https://github.com/llvm/llvm-project/commit/2554a85c0375b4c1c7c4f461811babef67e1a403.diff

LOG: [CodeGenPrepare][test] Add test for sinking of truncs demonstrating nsw/nuw are dropped

SinkCast creates a new cast with the same type and inputs, which drops
the nsw/nuw flags.

Reviewed as part of <https://github.com/llvm/llvm-project/pull/89904>
but split out so I can land the test separately.

Added: 
    llvm/test/Transforms/CodeGenPrepare/RISCV/noop-copy-sink.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/CodeGenPrepare/RISCV/noop-copy-sink.ll b/llvm/test/Transforms/CodeGenPrepare/RISCV/noop-copy-sink.ll
new file mode 100644
index 00000000000000..1b94bc798314ca
--- /dev/null
+++ b/llvm/test/Transforms/CodeGenPrepare/RISCV/noop-copy-sink.ll
@@ -0,0 +1,31 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' -mtriple=riscv64 %s \
+; RUN:   | FileCheck --check-prefixes=CHECK %s
+
+define i16 @sink_trunc1(i64 %a) {
+; CHECK-LABEL: @sink_trunc1(
+; CHECK-NEXT:  fnend:
+; CHECK-NEXT:    [[TMP0:%.*]] = trunc i64 [[A:%.*]] to i16
+; CHECK-NEXT:    ret i16 [[TMP0]]
+;
+  %trunc = trunc i64 %a to i16
+  br label %fnend
+
+fnend:
+  ret i16 %trunc
+}
+
+; The flags on the original trunc should be preserved.
+; FIXME: Flags are currently dropped.
+define i16 @sink_trunc2(i64 %a) {
+; CHECK-LABEL: @sink_trunc2(
+; CHECK-NEXT:  fnend:
+; CHECK-NEXT:    [[TMP0:%.*]] = trunc i64 [[A:%.*]] to i16
+; CHECK-NEXT:    ret i16 [[TMP0]]
+;
+  %trunc = trunc nuw nsw i64 %a to i16
+  br label %fnend
+
+fnend:
+  ret i16 %trunc
+}


        


More information about the llvm-commits mailing list