[PATCH] D17154: Bug fix: use dyn_cast_or_null instead of dyn_cast

Lawrence Hu via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 12 13:26:59 PST 2016


hulx2000 retitled this revision from "Bug fix: check nullptr before call dyn_cast" to "Bug fix: use dyn_cast_or_null instead of dyn_cast".
hulx2000 updated this revision to Diff 47850.

Repository:
  rL LLVM

http://reviews.llvm.org/D17154

Files:
  lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
  test/CodeGen/AArch64/gep-nullptr.ll

Index: test/CodeGen/AArch64/gep-nullptr.ll
===================================================================
--- /dev/null
+++ test/CodeGen/AArch64/gep-nullptr.ll
@@ -0,0 +1,31 @@
+; RUN: llc -O3 -aarch64-gep-opt=true   < %s
+; REQUIRES: asserts
+target datalayout = "e-m:e-i64:64-i128:128-n8:16:32:64-S128"
+target triple = "aarch64--linux-gnu"
+
+%struct.b_ctxt_t.23.226.487.516.545.661.690.719.748.777.1038.1219 = type { i8, i8, i8, i8, i8, i8, [4 x i8], i8, i8, [2 x i32], [2 x %union.MV.9.212.473.502.531.647.676.705.734.763.1024.1218], [4 x [2 x %union.MV.9.212.473.502.531.647.676.705.734.763.1024.1218]], [4 x [2 x %union.MV.9.212.473.502.531.647.676.705.734.763.1024.1218]], [4 x i8], i8*, i8*, i32, i8* }
+%union.MV.9.212.473.502.531.647.676.705.734.763.1024.1218 = type { i32 }
+
+; Function Attrs: argmemonly nounwind
+declare void @llvm.lifetime.end(i64, i8* nocapture)
+
+; Function Attrs: nounwind
+define void @test(%struct.b_ctxt_t.23.226.487.516.545.661.690.719.748.777.1038.1219* %mi_block) #1 {
+entry:
+  br i1 undef, label %for.body13.us, label %if.else
+
+; CHECK:  .text
+for.body13.us:                                    ; preds = %entry
+  %indvars.iv.next40 = or i64 0, 1
+  %packed4.i.us.1 = getelementptr inbounds %struct.b_ctxt_t.23.226.487.516.545.661.690.719.748.777.1038.1219, %struct.b_ctxt_t.23.226.487.516.545.661.690.719.748.777.1038.1219* %mi_block, i64 0, i32 11, i64 0, i64 %indvars.iv.next40, i32 0
+  call void @llvm.lifetime.end(i64 8, i8* nonnull undef) #2
+  unreachable
+
+if.else:                                          ; preds = %entry
+  ret void
+}
+
+attributes #0 = { argmemonly nounwind }
+attributes #1 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="cortex-a57" "target-features"="+crc,+crypto,+neon" "unsafe-fp-math"="true" "use-soft-float"="false" }
+attributes #2 = { nounwind }
+
Index: lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
===================================================================
--- lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
+++ lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
@@ -824,8 +824,8 @@
   // If we created a GEP with constant index, and the base is loop invariant,
   // then we swap the first one with it, so LICM can move constant GEP out
   // later.
-  GetElementPtrInst *FirstGEP = dyn_cast<GetElementPtrInst>(FirstResult);
-  GetElementPtrInst *SecondGEP = dyn_cast<GetElementPtrInst>(ResultPtr);
+  GetElementPtrInst *FirstGEP = dyn_cast_or_null<GetElementPtrInst>(FirstResult);
+  GetElementPtrInst *SecondGEP = dyn_cast_or_null<GetElementPtrInst>(ResultPtr);
   if (isSwapCandidate && isLegalToSwapOperand(FirstGEP, SecondGEP, L))
     swapGEPOperand(FirstGEP, SecondGEP);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17154.47850.patch
Type: text/x-patch
Size: 2888 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160212/79991600/attachment.bin>


More information about the llvm-commits mailing list