[llvm] fc9a507 - llvm-reduce: Reduce nuw/nsw flags from trunc
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 8 05:17:16 PDT 2024
Author: Matt Arsenault
Date: 2024-04-08T08:17:09-04:00
New Revision: fc9a5076c31139878da2fa12ef16090a58d55782
URL: https://github.com/llvm/llvm-project/commit/fc9a5076c31139878da2fa12ef16090a58d55782
DIFF: https://github.com/llvm/llvm-project/commit/fc9a5076c31139878da2fa12ef16090a58d55782.diff
LOG: llvm-reduce: Reduce nuw/nsw flags from trunc
Added:
Modified:
llvm/test/tools/llvm-reduce/reduce-flags.ll
llvm/tools/llvm-reduce/deltas/ReduceInstructionFlags.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-reduce/reduce-flags.ll b/llvm/test/tools/llvm-reduce/reduce-flags.ll
index 036bfdc84ac431..5d6d1260ac50e0 100644
--- a/llvm/test/tools/llvm-reduce/reduce-flags.ll
+++ b/llvm/test/tools/llvm-reduce/reduce-flags.ll
@@ -232,3 +232,35 @@ define i32 @or_disjoint_keep(i32 %a, i32 %b) {
%op = or disjoint i32 %a, %b
ret i32 %op
}
+
+; CHECK-LABEL: @trunc_nuw_drop(
+; INTERESTING: = trunc
+; RESULT: trunc i64
+define i32 @trunc_nuw_drop(i64 %a) {
+ %op = trunc nuw i64 %a to i32
+ ret i32 %op
+}
+
+; CHECK-LABEL: @trunc_nuw_keep(
+; INTERESTING: = trunc nuw
+; RESULT: trunc nuw i64
+define i32 @trunc_nuw_keep(i64 %a) {
+ %op = trunc nuw i64 %a to i32
+ ret i32 %op
+}
+
+; CHECK-LABEL: @trunc_nsw_drop(
+; INTERESTING: = trunc
+; RESULT: trunc i64
+define i32 @trunc_nsw_drop(i64 %a) {
+ %op = trunc nsw i64 %a to i32
+ ret i32 %op
+}
+
+; CHECK-LABEL: @trunc_nsw_keep(
+; INTERESTING: = trunc nsw
+; RESULT: trunc nsw i64
+define i32 @trunc_nsw_keep(i64 %a) {
+ %op = trunc nsw i64 %a to i32
+ ret i32 %op
+}
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceInstructionFlags.cpp b/llvm/tools/llvm-reduce/deltas/ReduceInstructionFlags.cpp
index 7b6fe7e5f91737..ad619a6c02a4d2 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceInstructionFlags.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceInstructionFlags.cpp
@@ -27,6 +27,11 @@ static void reduceFlagsInModule(Oracle &O, ReducerWorkItem &WorkItem) {
I.setHasNoSignedWrap(false);
if (OBO->hasNoUnsignedWrap() && !O.shouldKeep())
I.setHasNoUnsignedWrap(false);
+ } else if (auto *Trunc = dyn_cast<TruncInst>(&I)) {
+ if (Trunc->hasNoSignedWrap() && !O.shouldKeep())
+ Trunc->setHasNoSignedWrap(false);
+ if (Trunc->hasNoUnsignedWrap() && !O.shouldKeep())
+ Trunc->setHasNoUnsignedWrap(false);
} else if (auto *PE = dyn_cast<PossiblyExactOperator>(&I)) {
if (PE->isExact() && !O.shouldKeep())
I.setIsExact(false);
More information about the llvm-commits
mailing list