[PATCH] D111023: [ConstantFold] Refactor load folding

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 3 07:40:48 PDT 2021


nikic added inline comments.


================
Comment at: llvm/lib/Analysis/ConstantFolding.cpp:694
+  C = cast<Constant>(C->stripAndAccumulateConstantOffsets(
+          DL, Offset, /* AllowNonInbounds */ true));
+
----------------
Note that this already looks through aliases, so we don't need to handle that separately anymore.


================
Comment at: llvm/lib/Analysis/ConstantFolding.cpp:735
-  StringRef Str;
-  if (getConstantStringInfo(CE, Str) && !Str.empty()) {
-    size_t StrLen = Str.size();
----------------
I dropped this separate string handling code, because I believe it is redundant with the "reinterpret load" logic.


================
Comment at: llvm/test/Transforms/InstSimplify/ConstProp/loads.ll:250
 ; CHECK-LABEL: @test_array_of_zero_size_array(
-; CHECK-NEXT:    ret i64 0
+; CHECK-NEXT:    ret i64 undef
 ;
----------------
This is a read from a zero-size global. Both results are valid, this is an artifact of different code ordering.


================
Comment at: llvm/test/Transforms/InstSimplify/ConstProp/loads.ll:270
 ; CHECK-LABEL: @test_trailing_zero_gep_index(
-; CHECK-NEXT:    [[V:%.*]] = load {}*, {}** bitcast (i8* getelementptr inbounds (<{ [8 x i8], [8 x i8] }>, <{ [8 x i8], [8 x i8] }>* @g11, i64 0, i32 1, i64 0) to {}**), align 4
-; CHECK-NEXT:    ret {}* [[V]]
+; CHECK-NEXT:    ret {}* null
 ;
----------------
A side benefit of not relying on the original GEP structure.


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

https://reviews.llvm.org/D111023



More information about the llvm-commits mailing list