[AArch64][GlobalISel] Correct function evaluation order in applyINS
authorJessica Paquette <jpaquette@apple.com>
Wed, 24 Feb 2021 00:12:56 +0000 (16:12 -0800)
committerJessica Paquette <jpaquette@apple.com>
Wed, 24 Feb 2021 00:21:11 +0000 (16:21 -0800)
The order in which the nested calls to Builder.buildWhatever are
evaluated in differs between GCC and Clang.

This caused a bot failure because the MIR in the testcase was
coming out in a different order than expected.

Rather than using nested calls, pull them out in order to fix the
order of evaluation.

llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp

index 1eba655..3e05983 100644 (file)
@@ -456,11 +456,10 @@ static bool applyINS(MachineInstr &MI, MachineRegisterInfo &MRI,
   Register DstVec, SrcVec;
   int DstLane, SrcLane;
   std::tie(DstVec, DstLane, SrcVec, SrcLane) = MatchInfo;
-  Builder.buildInsertVectorElement(
-      Dst, DstVec,
-      Builder.buildExtractVectorElement(
-          ScalarTy, SrcVec, Builder.buildConstant(LLT::scalar(64), SrcLane)),
-      Builder.buildConstant(LLT::scalar(64), DstLane));
+  auto SrcCst = Builder.buildConstant(LLT::scalar(64), SrcLane);
+  auto Extract = Builder.buildExtractVectorElement(ScalarTy, SrcVec, SrcCst);
+  auto DstCst = Builder.buildConstant(LLT::scalar(64), DstLane);
+  Builder.buildInsertVectorElement(Dst, DstVec, Extract, DstCst);
   MI.eraseFromParent();
   return true;
 }