[llvm] r321857 - [GISel]: Don't create G_MUL with 1 during translation of GEP
Aditya Nandakumar via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 4 18:56:29 PST 2018
Author: aditya_nandakumar
Date: Thu Jan 4 18:56:28 2018
New Revision: 321857
URL: http://llvm.org/viewvc/llvm-project?rev=321857&view=rev
Log:
[GISel]: Don't create G_MUL with 1 during translation of GEP
When element size is 1, it's just wasteful to create MUL with 1.
https://reviews.llvm.org/D41738
Modified:
llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/trunk/test/CodeGen/AArch64/GlobalISel/translate-gep.ll
Modified: llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp?rev=321857&r1=321856&r2=321857&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp Thu Jan 4 18:56:28 2018
@@ -516,10 +516,6 @@ bool IRTranslator::translateGetElementPt
Offset = 0;
}
- // N = N + Idx * ElementSize;
- unsigned ElementSizeReg =
- getOrCreateVReg(*ConstantInt::get(OffsetIRTy, ElementSize));
-
unsigned IdxReg = getOrCreateVReg(*Idx);
if (MRI->getType(IdxReg) != OffsetTy) {
unsigned NewIdxReg = MRI->createGenericVirtualRegister(OffsetTy);
@@ -527,11 +523,20 @@ bool IRTranslator::translateGetElementPt
IdxReg = NewIdxReg;
}
- unsigned OffsetReg = MRI->createGenericVirtualRegister(OffsetTy);
- MIRBuilder.buildMul(OffsetReg, ElementSizeReg, IdxReg);
+ // N = N + Idx * ElementSize;
+ // Avoid doing it for ElementSize of 1.
+ unsigned GepOffsetReg;
+ if (ElementSize != 1) {
+ unsigned ElementSizeReg =
+ getOrCreateVReg(*ConstantInt::get(OffsetIRTy, ElementSize));
+
+ GepOffsetReg = MRI->createGenericVirtualRegister(OffsetTy);
+ MIRBuilder.buildMul(GepOffsetReg, ElementSizeReg, IdxReg);
+ } else
+ GepOffsetReg = IdxReg;
unsigned NewBaseReg = MRI->createGenericVirtualRegister(PtrTy);
- MIRBuilder.buildGEP(NewBaseReg, BaseReg, OffsetReg);
+ MIRBuilder.buildGEP(NewBaseReg, BaseReg, GepOffsetReg);
BaseReg = NewBaseReg;
}
}
Modified: llvm/trunk/test/CodeGen/AArch64/GlobalISel/translate-gep.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/GlobalISel/translate-gep.ll?rev=321857&r1=321856&r2=321857&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/translate-gep.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/translate-gep.ll Thu Jan 4 18:56:28 2018
@@ -3,6 +3,15 @@
%type = type [4 x {i8, i32}]
+define i8* @translate_element_size1(i64 %arg) {
+; CHECK-LABEL: name: translate_element_size1
+; CHECK: [[OFFSET:%[0-9]+]]:_(s64) = COPY %x0
+; CHECK: [[BASE:%[0-9]+]]:_(p0) = G_CONSTANT i64 0
+; CHECK: [[GEP:%[0-9]+]]:_(p0) = G_GEP [[BASE]], [[OFFSET]]
+ %tmp = getelementptr i8, i8* null, i64 %arg
+ ret i8* %tmp
+}
+
define %type* @first_offset_const(%type* %addr) {
; CHECK-LABEL: name: first_offset_const
More information about the llvm-commits
mailing list