summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2024-04-04 11:06:52 -0400
committerMatt Arsenault <arsenm2@gmail.com>2024-04-08 08:17:09 -0400
commitfc9a5076c31139878da2fa12ef16090a58d55782 (patch)
tree8cda64399b2ed971b0f08a448acca05a4706a6f2
parentacb2a475766b621fe7e5d792ff7948a5794c3e87 (diff)
llvm-reduce: Reduce nuw/nsw flags from trunc
-rw-r--r--llvm/test/tools/llvm-reduce/reduce-flags.ll32
-rw-r--r--llvm/tools/llvm-reduce/deltas/ReduceInstructionFlags.cpp5
2 files changed, 37 insertions, 0 deletions
diff --git a/llvm/test/tools/llvm-reduce/reduce-flags.ll b/llvm/test/tools/llvm-reduce/reduce-flags.ll
index 036bfdc84ac4..5d6d1260ac50 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 7b6fe7e5f917..ad619a6c02a4 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);