[llvm] r239015 - [ConstantFold] Don't skip the first gep index when folding geps
David Majnemer
david.majnemer at gmail.com
Thu Jun 4 00:01:57 PDT 2015
Author: majnemer
Date: Thu Jun 4 02:01:56 2015
New Revision: 239015
URL: http://llvm.org/viewvc/llvm-project?rev=239015&view=rev
Log:
[ConstantFold] Don't skip the first gep index when folding geps
We neglected to check if the first index made the GEP ineligible for
'inbounds'.
This fixes PR23753.
Added:
llvm/trunk/test/Transforms/LoopStrengthReduce/pr23753.ll
Modified:
llvm/trunk/lib/IR/ConstantFold.cpp
Modified: llvm/trunk/lib/IR/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantFold.cpp?rev=239015&r1=239014&r2=239015&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp (original)
+++ llvm/trunk/lib/IR/ConstantFold.cpp Thu Jun 4 02:01:56 2015
@@ -2165,9 +2165,9 @@ static Constant *ConstantFoldGetElementP
// factored out into preceding dimensions.
bool Unknown = false;
SmallVector<Constant *, 8> NewIdxs;
- Type *Ty = PointeeTy;
- Type *Prev = C->getType();
- for (unsigned i = 1, e = Idxs.size(); i != e;
+ Type *Ty = C->getType();
+ Type *Prev = nullptr;
+ for (unsigned i = 0, e = Idxs.size(); i != e;
Prev = Ty, Ty = cast<CompositeType>(Ty)->getTypeAtIndex(Idxs[i]), ++i) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(Idxs[i])) {
if (isa<ArrayType>(Ty) || isa<VectorType>(Ty))
Added: llvm/trunk/test/Transforms/LoopStrengthReduce/pr23753.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopStrengthReduce/pr23753.ll?rev=239015&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/LoopStrengthReduce/pr23753.ll (added)
+++ llvm/trunk/test/Transforms/LoopStrengthReduce/pr23753.ll Thu Jun 4 02:01:56 2015
@@ -0,0 +1,29 @@
+; RUN: opt < %s -loop-reduce -S | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at a = external global i32, align 4
+ at d = external global i8, align 1
+
+; CHECK-LABEL: void @f
+define void @f() {
+entry:
+ br label %for.body
+
+for.body:
+ %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
+ %arrayidx = getelementptr inbounds i32, i32* @a, i64 %indvars.iv
+ %cmp = icmp ne i32* %arrayidx, bitcast (i8* @d to i32*)
+ %indvars.iv.next = add i64 %indvars.iv, 1
+ br i1 %cmp, label %for.body, label %for.end
+
+; CHECK: %[[phi:.*]] = phi i8* [ %[[gep:.*]], {{.*}} ], [ getelementptr (i8, i8* @d, i64 sub (i64 4, i64 ptrtoint (i32* @a to i64))), {{.*}} ]
+; CHECK-NEXT: %[[gep]] = getelementptr i8, i8* %[[phi]], i64 -4
+; CHECK-NEXT: %[[cst:.*]] = bitcast i8* %[[gep]] to i32*
+; CHECK-NEXT: %[[cmp:.*]] = icmp ne i32* %[[cst]], null
+; CHECK-NEXT: br i1 %[[cmp]]
+
+for.end:
+ ret void
+}
More information about the llvm-commits
mailing list