This patch canonicalizes constant expression GEPs to use i8 source element type, aka ptradd. This is the ConstantFolding equivalent of the InstCombine canonicalization introduced in #68882. I believe all our optimizations working on constant expression GEPs (like GlobalOpt etc) have already been switched to work on offsets, so I don't expect any significant fallout from this change. This is part of: https://discourse.llvm.org/t/rfc-replacing-getelementptr-with-ptradd/68699
31 lines
1.0 KiB
LLVM
31 lines
1.0 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt < %s -passes=newgvn -S | FileCheck %s
|
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
|
|
|
%rec11 = type { i16, i16, i16 }
|
|
|
|
@str = global %rec11 { i16 1, i16 2, i16 3 }
|
|
|
|
;; Test that we forward the first store to the second load
|
|
define i16 @bazinga() {
|
|
; CHECK-LABEL: @bazinga(
|
|
; CHECK-NEXT: [[_TMP10:%.*]] = load i16, ptr getelementptr inbounds (i8, ptr @str, i64 2), align 2
|
|
; CHECK-NEXT: store i16 [[_TMP10]], ptr @str, align 2
|
|
; CHECK-NEXT: [[_TMP15:%.*]] = icmp eq i16 [[_TMP10]], 3
|
|
; CHECK-NEXT: [[_TMP16:%.*]] = select i1 [[_TMP15]], i16 1, i16 0
|
|
; CHECK-NEXT: br label [[BB1:%.*]]
|
|
; CHECK: bb1:
|
|
; CHECK-NEXT: ret i16 [[_TMP16]]
|
|
;
|
|
%_tmp9 = getelementptr %rec11, ptr @str, i16 0, i32 1
|
|
%_tmp10 = load i16, ptr %_tmp9
|
|
store i16 %_tmp10, ptr @str
|
|
%_tmp14 = load i16, ptr @str
|
|
%_tmp15 = icmp eq i16 %_tmp14, 3
|
|
%_tmp16 = select i1 %_tmp15, i16 1, i16 0
|
|
br label %bb1
|
|
|
|
bb1:
|
|
ret i16 %_tmp16
|
|
}
|