[llvm] 30b5c3f - [Local] Emit nsw for inbounds offset calculation
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 13 09:39:57 PST 2020
Author: Nikita Popov
Date: 2020-11-13T18:39:46+01:00
New Revision: 30b5c3f3a647ce9c5d3d2db5439592f9f00697c7
URL: https://github.com/llvm/llvm-project/commit/30b5c3f3a647ce9c5d3d2db5439592f9f00697c7
DIFF: https://github.com/llvm/llvm-project/commit/30b5c3f3a647ce9c5d3d2db5439592f9f00697c7.diff
LOG: [Local] Emit nsw for inbounds offset calculation
In line with D90708, we can use nsw for the inbounds offset
calculation -- the muls were already using nsw, but the adds were
not.
Added:
Modified:
llvm/include/llvm/Analysis/Utils/Local.h
llvm/test/Transforms/InstCombine/sub-gep.ll
llvm/test/Transforms/InstCombine/sub.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/Utils/Local.h b/llvm/include/llvm/Analysis/Utils/Local.h
index f8892c85e1458..bd82b34165d66 100644
--- a/llvm/include/llvm/Analysis/Utils/Local.h
+++ b/llvm/include/llvm/Analysis/Utils/Local.h
@@ -90,7 +90,8 @@ Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP,
}
if (Result)
- Result = Builder->CreateAdd(Result, Offset, GEP->getName().str()+".offs");
+ Result = Builder->CreateAdd(Result, Offset, GEP->getName().str()+".offs",
+ false /*NUW*/, isInBounds /*NSW*/);
else
Result = Offset;
}
diff --git a/llvm/test/Transforms/InstCombine/sub-gep.ll b/llvm/test/Transforms/InstCombine/sub-gep.ll
index 47dd0ce72f838..9868ed1cdf575 100644
--- a/llvm/test/Transforms/InstCombine/sub-gep.ll
+++ b/llvm/test/Transforms/InstCombine/sub-gep.ll
@@ -143,8 +143,8 @@ define i64 @test_inbounds_nuw_multi_index([0 x [2 x i32]]* %base, i64 %idx, i64
; CHECK-LABEL: @test_inbounds_nuw_multi_index(
; CHECK-NEXT: [[P2_IDX:%.*]] = shl nsw i64 [[IDX:%.*]], 3
; CHECK-NEXT: [[P2_IDX1:%.*]] = shl nsw i64 [[IDX2:%.*]], 2
-; CHECK-NEXT: [[P2_OFFS2:%.*]] = add i64 [[P2_IDX]], [[P2_IDX1]]
-; CHECK-NEXT: ret i64 [[P2_OFFS2]]
+; CHECK-NEXT: [[P2_OFFS:%.*]] = add nsw i64 [[P2_IDX]], [[P2_IDX1]]
+; CHECK-NEXT: ret i64 [[P2_OFFS]]
;
%p1 = getelementptr inbounds [0 x [2 x i32]], [0 x [2 x i32]]* %base, i64 0, i64 0, i64 0
%p2 = getelementptr inbounds [0 x [2 x i32]], [0 x [2 x i32]]* %base, i64 0, i64 %idx, i64 %idx2
diff --git a/llvm/test/Transforms/InstCombine/sub.ll b/llvm/test/Transforms/InstCombine/sub.ll
index 3e9c066dfbf3a..d9c67d0568f74 100644
--- a/llvm/test/Transforms/InstCombine/sub.ll
+++ b/llvm/test/Transforms/InstCombine/sub.ll
@@ -1075,8 +1075,8 @@ define i64 @test58([100 x [100 x i8]]* %foo, i64 %i, i64 %j) {
; "%sub = i64 %i, %j, ret i64 %sub"
; gep1 and gep2 have only one use
; CHECK-LABEL: @test58(
-; CHECK-NEXT: [[GEP1_OFFS:%.*]] = add i64 [[I:%.*]], 4200
-; CHECK-NEXT: [[GEP2_OFFS:%.*]] = add i64 [[J:%.*]], 4200
+; CHECK-NEXT: [[GEP1_OFFS:%.*]] = add nsw i64 [[I:%.*]], 4200
+; CHECK-NEXT: [[GEP2_OFFS:%.*]] = add nsw i64 [[J:%.*]], 4200
; CHECK-NEXT: [[GEPDIFF:%.*]] = sub i64 [[GEP1_OFFS]], [[GEP2_OFFS]]
; CHECK-NEXT: ret i64 [[GEPDIFF]]
;
More information about the llvm-commits
mailing list