[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 11:39:33 PDT 2022
w2yehia updated this revision to Diff 434552.
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/2011-06-13-nsw-alloca.ll
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,15 @@
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+declare void @use(i32 *)
+
+define void @foo(i64 %X) {
+; Currently we cannot handle expressions of the form Offset - X * Scale.
+; CHECK: mul nsw i64 %X, -4
+; CHECK: alloca i8
+ %1 = mul nsw i64 %X, -4
+ %2 = add nsw i64 %1, 24
+ %3 = alloca i8, i64 %2, align 4
+ %4 = bitcast i8* %3 to i32*
+ call void @use(i32 *%4)
+ ret void
+}
+
Index: llvm/test/Transforms/InstCombine/2011-06-13-nsw-alloca.ll
===================================================================
--- llvm/test/Transforms/InstCombine/2011-06-13-nsw-alloca.ll
+++ llvm/test/Transforms/InstCombine/2011-06-13-nsw-alloca.ll
@@ -15,9 +15,9 @@
; <label>:4 ; preds = %0
%5 = load i32, i32* %1, align 4
- %6 = shl nsw i32 %5, 3
-; With "nsw", the alloca and its bitcast can be fused:
- %7 = add nsw i32 %6, 2048
+ %6 = shl nuw i32 %5, 3
+; With "nuw", the alloca and its bitcast can be fused:
+ %7 = add nuw i32 %6, 2048
; CHECK: alloca double
%8 = alloca i8, i32 %7
%9 = bitcast i8* %8 to double*
@@ -45,8 +45,8 @@
; <label>:4 ; preds = %0
%5 = load i32, i32* %1, align 4
- %6 = mul nsw i32 %5, 8
-; Without "nsw", the alloca and its bitcast cannot be fused:
+ %6 = mul nuw i32 %5, 8
+; Without "nuw", the alloca and its bitcast cannot be fused:
%7 = add i32 %6, 2048
; CHECK: alloca i8
%8 = alloca i8, i32 %7
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.434552.patch
Type: text/x-patch
Size: 2280 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220606/476d1d79/attachment.bin>
More information about the llvm-commits
mailing list