[PATCH] D126546: [InstCombine] decomposeSimpleLinearExpr should bail out on negative operands.

wael yehia via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 6 07:10:15 PDT 2022


w2yehia updated this revision to Diff 434461.
w2yehia added a comment.

As per review, remove `!OBI->hasNoSignedWrap()` from the early exit condition. Also the original fix is no longer needed so remove it as well.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126546/new/

https://reviews.llvm.org/D126546

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/test/Transforms/InstCombine/neg-alloca.ll


Index: llvm/test/Transforms/InstCombine/neg-alloca.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/neg-alloca.ll
@@ -0,0 +1,29 @@
+; RUN: opt -S -passes=instcombine < %s | FileCheck %s
+ at test = external global [1 x i32], align 16
+
+define void @foo() {
+  br label %b0
+
+b0:
+  %1 = phi i64 [ 1, %0 ], [ %9, %b0 ]
+; Currently we cannot handle expressions of the form Offset - X * Scale.
+; CHECK: mul nsw i64 %1, -4
+; CHECK: alloca i8
+  %2 = mul nsw i64 %1, -4
+  %3 = add nsw i64 %2, 24
+  %4 = alloca i8, i64 %3, align 4
+  %5 = bitcast i8* %4 to i32*
+  store i32 undef, i32* %5, align 4
+
+  %6 = load i8, i8* %4, align 4
+  %7 = getelementptr inbounds [1 x i32], [1 x i32]* @test, i64 0, i8 %6
+  %8 = load i32, i32* %7, align 4
+  store i32 %8, i32* undef, align 4
+
+  %9 = add nuw nsw i64 %1, 1
+  br i1 undef, label %bend, label %b0
+
+bend:
+  ret void
+}
+
Index: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -37,7 +37,7 @@
   if (BinaryOperator *I = dyn_cast<BinaryOperator>(Val)) {
     // Cannot look past anything that might overflow.
     OverflowingBinaryOperator *OBI = dyn_cast<OverflowingBinaryOperator>(Val);
-    if (OBI && !OBI->hasNoUnsignedWrap() && !OBI->hasNoSignedWrap()) {
+    if (OBI && !OBI->hasNoUnsignedWrap()) {
       Scale = 1;
       Offset = 0;
       return Val;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126546.434461.patch
Type: text/x-patch
Size: 1575 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220606/887521ec/attachment.bin>


More information about the llvm-commits mailing list