[PATCH] D30228: [Reassociate] Add negated value of negative constant to the Duplicates list.
Chad Rosier via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 23 11:00:46 PST 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL296003: [Reassociate] Add negated value of negative constant to the Duplicates list. (authored by mcrosier).
Changed prior to commit:
https://reviews.llvm.org/D30228?vs=89405&id=89537#toc
Repository:
rL LLVM
https://reviews.llvm.org/D30228
Files:
llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
llvm/trunk/test/Transforms/Reassociate/basictest.ll
Index: llvm/trunk/test/Transforms/Reassociate/basictest.ll
===================================================================
--- llvm/trunk/test/Transforms/Reassociate/basictest.ll
+++ llvm/trunk/test/Transforms/Reassociate/basictest.ll
@@ -222,3 +222,23 @@
; CHECK-LABEL: @test15
; CHECK: and i1 %A, %B
}
+
+; PR30256 - previously this asserted.
+; CHECK-LABEL: @test16
+; CHECK: %[[FACTOR:.*]] = mul i64 %a, -4
+; CHECK-NEXT: %[[RES:.*]] = add i64 %[[FACTOR]], %b
+; CHECK-NEXT: ret i64 %[[RES]]
+define i64 @test16(i1 %cmp, i64 %a, i64 %b) {
+entry:
+ %shl = shl i64 %a, 1
+ %shl.neg = sub i64 0, %shl
+ br i1 %cmp, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ %add1 = add i64 %shl.neg, %shl.neg
+ %add2 = add i64 %add1, %b
+ ret i64 %add2
+
+if.end: ; preds = %entry
+ ret i64 0
+}
Index: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
+++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
@@ -1520,8 +1520,8 @@
if (ConstantInt *CI = dyn_cast<ConstantInt>(Factor)) {
if (CI->isNegative() && !CI->isMinValue(true)) {
Factor = ConstantInt::get(CI->getContext(), -CI->getValue());
- assert(!Duplicates.count(Factor) &&
- "Shouldn't have two constant factors, missed a canonicalize");
+ if (!Duplicates.insert(Factor).second)
+ continue;
unsigned Occ = ++FactorOccurrences[Factor];
if (Occ > MaxOcc) {
MaxOcc = Occ;
@@ -1533,8 +1533,8 @@
APFloat F(CF->getValueAPF());
F.changeSign();
Factor = ConstantFP::get(CF->getContext(), F);
- assert(!Duplicates.count(Factor) &&
- "Shouldn't have two constant factors, missed a canonicalize");
+ if (!Duplicates.insert(Factor).second)
+ continue;
unsigned Occ = ++FactorOccurrences[Factor];
if (Occ > MaxOcc) {
MaxOcc = Occ;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30228.89537.patch
Type: text/x-patch
Size: 2118 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170223/10e79f76/attachment.bin>
More information about the llvm-commits
mailing list