[PATCH] D144333: [DivRemPairs] Strip division's poison generating flagGiven this transformation: X % Y -> X - (X / Y) * YThis patch strips off the poison-generating flag of X / Y such as exact, because it may make the optimized form result poison whereas X % Y...
Juneyoung Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 18 12:47:48 PST 2023
aqjune created this revision.
aqjune added reviewers: nikic, lebedev.ri, resistor.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
aqjune requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
...does not.
The issue was reported here: https://github.com/llvm/llvm-project/issues/60748
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D144333
Files:
llvm/lib/Transforms/Scalar/DivRemPairs.cpp
llvm/test/Transforms/DivRemPairs/AArch64/div-rem-pairs.ll
Index: llvm/test/Transforms/DivRemPairs/AArch64/div-rem-pairs.ll
===================================================================
--- llvm/test/Transforms/DivRemPairs/AArch64/div-rem-pairs.ll
+++ llvm/test/Transforms/DivRemPairs/AArch64/div-rem-pairs.ll
@@ -5,7 +5,7 @@
; CHECK-LABEL: @f(
; CHECK-NEXT: [[DOTFROZEN:%.*]] = freeze i8 [[TMP1:%.*]]
; CHECK-NEXT: [[DOTFROZEN1:%.*]] = freeze i8 [[TMP2:%.*]]
-; CHECK-NEXT: [[TMP4:%.*]] = udiv exact i8 [[DOTFROZEN]], [[DOTFROZEN1]]
+; CHECK-NEXT: [[TMP4:%.*]] = udiv i8 [[DOTFROZEN]], [[DOTFROZEN1]]
; CHECK-NEXT: [[TMP5:%.*]] = mul i8 [[TMP4]], [[DOTFROZEN1]]
; CHECK-NEXT: [[DOTDECOMPOSED:%.*]] = sub i8 [[DOTFROZEN]], [[TMP5]]
; CHECK-NEXT: store i8 [[DOTDECOMPOSED]], ptr [[TMP0:%.*]], align 1
Index: llvm/lib/Transforms/Scalar/DivRemPairs.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/DivRemPairs.cpp
+++ llvm/lib/Transforms/Scalar/DivRemPairs.cpp
@@ -371,6 +371,11 @@
Mul->insertAfter(RemInst);
Sub->insertAfter(Mul);
+ // If DivInst has the exact flag, remove it. Otherwise this optimization
+ // may replace a well-defined value 'X % Y' with poison.
+ if (DivInst->hasPoisonGeneratingFlags())
+ DivInst->dropPoisonGeneratingFlags();
+
// If X can be undef, X should be frozen first.
// For example, let's assume that Y = 1 & X = undef:
// %div = sdiv undef, 1 // %div = undef
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144333.498618.patch
Type: text/x-patch
Size: 1478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230218/3b8fa2be/attachment.bin>
More information about the llvm-commits
mailing list