[llvm] 5a5a808 - [BasicAA] Retain shl nowrap flags in GetLinearExpression()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 27 04:28:49 PDT 2021
Author: Nikita Popov
Date: 2021-03-27T12:26:22+01:00
New Revision: 5a5a8088cc8d3f9fdca8c959dd3e48da13324aab
URL: https://github.com/llvm/llvm-project/commit/5a5a8088cc8d3f9fdca8c959dd3e48da13324aab
DIFF: https://github.com/llvm/llvm-project/commit/5a5a8088cc8d3f9fdca8c959dd3e48da13324aab.diff
LOG: [BasicAA] Retain shl nowrap flags in GetLinearExpression()
Nowrap flags between mul and shl differ in that mul nsw allows
multiplication of 1 * INT_MIN, while shl nsw does not. This means
that it is always fine to transfer shl nowrap flags to muls, but
not necessarily the other way around. In this case the NUW/NSW
results refer to mul/add operations, so it's fine to retain the
flags from the shl.
Added:
Modified:
llvm/lib/Analysis/BasicAliasAnalysis.cpp
llvm/test/Analysis/BasicAA/zext.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index acf7bef3aeb04..6246cad667768 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -314,10 +314,7 @@ static bool isObjectSize(const Value *V, uint64_t Size, const DataLayout &DL,
Offset <<= RHS.getLimitedValue();
Scale <<= RHS.getLimitedValue();
- // the semantics of nsw and nuw for left shifts don't match those of
- // multiplications, so we won't propagate them.
- NSW = NUW = false;
- return V;
+ break;
}
if (isa<OverflowingBinaryOperator>(BOp)) {
diff --git a/llvm/test/Analysis/BasicAA/zext.ll b/llvm/test/Analysis/BasicAA/zext.ll
index 39e67dcca74ce..2e25734be775c 100644
--- a/llvm/test/Analysis/BasicAA/zext.ll
+++ b/llvm/test/Analysis/BasicAA/zext.ll
@@ -240,5 +240,29 @@ entry:
ret float %x4
}
+; CHECK-LABEL: Function: test_shl_nuw_zext
+; CHECK: MustAlias: i8* %p.1, i8* %p.2
+define void @test_shl_nuw_zext(i8* %p, i32 %x) {
+ %shl = shl nuw i32 %x, 1
+ %shl.ext = zext i32 %shl to i64
+ %ext = zext i32 %x to i64
+ %ext.shl = shl nuw i64 %ext, 1
+ %p.1 = getelementptr i8, i8* %p, i64 %shl.ext
+ %p.2 = getelementptr i8, i8* %p, i64 %ext.shl
+ ret void
+}
+
+; CHECK-LABEL: Function: test_shl_nsw_sext
+; CHECK: MustAlias: i8* %p.1, i8* %p.2
+define void @test_shl_nsw_sext(i8* %p, i32 %x) {
+ %shl = shl nsw i32 %x, 1
+ %shl.ext = sext i32 %shl to i64
+ %ext = sext i32 %x to i64
+ %ext.shl = shl nsw i64 %ext, 1
+ %p.1 = getelementptr i8, i8* %p, i64 %shl.ext
+ %p.2 = getelementptr i8, i8* %p, i64 %ext.shl
+ ret void
+}
+
; Function Attrs: nounwind
declare noalias i8* @malloc(i64)
More information about the llvm-commits
mailing list